我的豆子看起来像这样:
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"}
预计每个JacksonFeatureUnwrapping 文档。为什么我没有得到展开的结果?