【发布时间】:2015-04-07 15:25:55
【问题描述】:
一个 JSON 字符串,如:
[
"a", "b", "c"
]
通常会反序列化为List<String>。但我有一个看起来像这样的类:
public class Foo {
private List<String> theList;
public Foo(List<String> theList) {
this.theList = theList;
}
public String toString() {
return new ObjectMapper().writeValueAsString(theList);
}
// ... more methods
}
现在我想将上面的 JSON 字符串反序列化为 Foo 类的对象,例如:
Foo foo = new ObjectMapper().readValue(jsonString, Foo.class);
这怎么可能?
我已经尝试将@JsonCreator 与构造函数一起使用,但总是得到:
JsonMappingException: Can not deserialize instance of ... out of START_ARRAY token
【问题讨论】:
标签: java json serialization jackson deserialization