简体   繁体   中英

Java jackson embedded object deserialization

I have in response

{
   "item": {
     "field1": 1,
     "field2": 1,
   }
}

I want to deserialize it to Privacy class with 2 fields field1 and field2 .

A have added

objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, unwrapRootValue);

But now I receive an exception

org.codehaus.jackson.map.JsonMappingException: Root name 'item' does not match expected ('Privacy') for type [simple type, class com.myproj.Privacy]

How can I map this class to json object?

我找到了答案:我们必须在类中添加@JsonRootName(value = "item")注释。

您可以使用Flexjson反序列序列

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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