Java Arraylist 无法从 START_OBJECT 令牌反序列化实例

问题描述

出现错误

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());
        

地图响应

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;
}
    
        

课程:

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;
    }
}

    
        

课程:

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;
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)