为什么我无法使用 Jackson Java 库解开和序列化 Java 映射?
我的豆子看起来像这样:
class MyBean {
private @JsonUnwrapped HashMap<String, String> map = new HashMap<String, String>();
private String name;
public HashMap<String, String> getMap() {
return map;
}
public void setMap(HashMap<String, String> map) {
this.map = map;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
当我使用以下代码序列化Bean时:
MyBean bean = new MyBean();
HashMap<String, String> map = new HashMap<String, String>();;
map.put("key1", "value1");
map.put("key2", "value2");
bean.setMap(map);
bean.setName("suren");
ObjectMapper mapper = new ObjectMapper();
System.out.println("\n"+mapper.writeValueAsString(bean));
我得到的结果是这样的:
{"map":{"key2":"value2","key1":"value1"},"name":"suren"}
但
{"key2":"value2","key1":"value1","name":"suren"}
根据 JacksonFeatureUnpacking 文档进行预估。为什么我没有得到未包装的结果?