1

Getting the error:

java.lang.IllegalArgumentException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
java.lang.IllegalArgumentException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
java.lang.IllegalArgumentException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

   

ServiceImpl:

List<CarType> carTypeList=MapResponse.getCarTypes(response.getResponseBody());
        

MapResponse

public static java.util.List<com.abc.first.model.CarType> getCarTypes(Object response) {
    java.util.List<com.abc.second.model.CarType> Response = objectMapper.convertValue(response,
            new TypeReference<List<com.abc.second.model.CarType>>() {
            });

    java.util.List<com.abc.first.model.CarType> Response2 = new java.util.ArrayList();

    com.abc.first.model.CarType mobModel = null;
    for (com.abc.second.model.CarType hmbModel : Response) {
        mobModel = new com.abc.first.model.CarType();
        mobModel.setId(hmbModel.getId());
        mobModel.setName(hmbModel.getName());
        Response2 .add(mobModel);
    }
    return Response2;
}
    
        

Classes:

com.abc.first.model.CarType:

public class CarType{
    private int id;
    private String name;

    public CarType(int id) {
        this.id = id;
    }

    public CarType(String name) {
        this.name = name;
    }

    public CarType(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public CarType() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

    
        

Classes:

com.abc.second.model.CarType:

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_NULL)
public class CarType {
    private int id;
    private String name;

    public CarType () {
    }

    public CarType (String name) {
        this.name = name;
    }

    public CarType (int id) {
        this.id = id;
    }

    public CarType (int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
azro
  • 53,056
  • 7
  • 34
  • 70

0 Answers0