我想使用 jackson-databind 将一个 json 反序列化为一个包含其他对象列表的对象。
我正在尝试在 json 下反序列化。我有 Class class1,它有一个List<NestedProp>. Prop2 是一个数组列表。List<NestedProp> prop2.
结构类`
class Class1 {
String prop1;
List<NestedProp> prop2;
//setters getters
}
class NestedProp {
String p1;
String p2;
//setters getters
}
`
```
"class1": {
"prop1": "pp",
"prop2": [
{
"nestedProp": [
{
"p1": "127",
"p2": "1"
},
{
"p1": "128",
"p2": "2"
}
]
}
]
}
While deserialisingI get the below exception:
>com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `NestedProp` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('127')
at [Source: (File); line: 59, column: 7] (through reference chain: java.util.ArrayList[1]->Class1["prop2"]->java.util.ArrayList[0])
List<Class1> testData = objectMapper.readValue(test.json, Class1.class);
蝴蝶不菲
相关分类