简体   繁体   English

杰克逊-无法反序列化字符串列表

[英]Jackson - Cannot deserialize list of strings

On both sides I have: 双方都有:

Class ListWrapper {
    public List<String> l;
    ListWrapper(List<String> l) {
        this.l = l;
    }
}

On the client side I have: 在客户端,我有:

    ObjectMapper mapper = new ObjectMapper();
String fl;
    try {
        fl = mapper.writeValueAsString(new ListWrapper(u.getList()));
    } catch (IOException e) {
        fl = "null";
    }

On the server side I have: 在服务器端,我有:

String data = getQuery().........;
List l = new ObjectMapper.readValue(data,ListWrapper.class).list;

Yet I'm getting: 但是我得到了:

org.codehaus.jackson.map.JsonMappingException: Can not create Bean deserializer for ([simple type, class il.ac.technion.ssdl.hitch.resource.ListWrapper]): neither default/delegating constructor nor factory methods found

When I'm trying to deserialize the list. 当我尝试反序列化列表时。

EDIT: 编辑:

When printing the list on the client side I'm getting: 在客户端上打印列表时,我得到:

 {"list":["v1","v2,"v3"]}

default/delegating constructor nor factory methods found 默认/委托构造函数或工厂方法均未找到

Probably your ListWrapper class is missing a default constructor. 您的ListWrapper类可能缺少默认的构造函数。

public ListWrapper(){
}

You JSON string is incorrect: 您的JSON字符串不正确:

{"list":["v1","v2,"v3"]} <<<--- double quotes missing after v2 ! {“ list”:[“ v1”,“ v2,” v3“]} <<< --- v2之后缺少双引号!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM