My bean looks like this:
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;
}
}
While I'm serializing the bean using the following code:
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("
"+mapper.writeValueAsString(bean));
I'm getting result like this:
{"map":{"key2":"value2","key1":"value1"},"name":"suren"}
but
{"key2":"value2","key1":"value1","name":"suren"}
is expected per the JacksonFeatureUnwrapping documentation. Why am I not getting the unwrapped result?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…