我有回应
{
"item": {
"field1": 1,
"field2": 1,
}
}
我想将其反序列化为Privacy
类,包含2个字段field1
和field2
。
A已添加
objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, unwrapRootValue);
但现在我收到了一个例外
org.codehaus.jackson.map.JsonMappingException: Root name 'item' does not match expected ('Privacy') for type [simple type, class com.myproj.Privacy]
如何将此类映射到json对象?
答案 0 :(得分:4)
我找到了答案:我们必须在课堂上添加@JsonRootName(value = "item")
注释。
答案 1 :(得分:0)
您可以使用Flexjson反序列化 Deserialize