[英]Object Mapper deserializing map array
{
"name" : "test",
"info": [
{
"key1": "test",
"key2": "blaa",
"key3": "yadayada"
},
{
"key4": "test1",
"key5": "blaa1",
"key6": "yadayada1"
}
],
}
I have this class for the deserialization 我有这个班的反序列化
public class Account{
private String name;
private Map<String,String>[] info;
}
for some reason info
is not getting deserialized... not even with List<Map<String,String>>
its always null, and name
is working 由于某种原因,
info
不会反序列化...即使使用List<Map<String,String>>
也不总是反序列化,并且name
始终为null
(im using ObjectMapper
) (即使用
ObjectMapper
)
the code 编码
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
results = objectMapper.readValue(responseBody.getEntity().getContent(), Account.class);
Thanks 谢谢
The problem lies on the fact that the JSON schema you posted has a wrong comma in the end ) . 问题在于您发布的JSON模式末尾带有错误的逗号 )。 Try the following
尝试以下
Let's say that the responseBody.getEntity().getContent()
is the JSON
you posted 假设
responseBody.getEntity().getContent()
是您发布的JSON
Account.java Account.java
or more specific 或更具体
private String name;
private Map<String,String>[] info;
//getters && setters && default constructor
Deserialization method 反序列化方法
Account account = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
account = objectMapper.readValue(responseBody.getEntity().getContent(), Account.class);
} catch (IOException e) {
e.printStackTrace();
}
This is a mixed bag of things wrong. 这是错杂的事情。
Account
) Account
) name
field is de-serialized, which I imagine implies some accessible setter is actually there but you may not have posted it? name
字段已反序列化,我想这实际上意味着确实存在一些可访问的设置器,但您可能还没有发布它? info
silently fails to serialize, it's likely because your ObjectMapper
has been configured with DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
as false
- see docs . info
静静地失败序列化,因为你很可能ObjectMapper
已经配置了DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
为false
看到- 文档 。 List<Map<String, String>>
for info
, or keep the Map<String, String>[]
- it's not relevant to your issue. List<Map<String, String>>
作为info
,或保留Map<String, String>[]
-与您的问题无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.