姬長信(Redy)

为什么我无法使用Jackson Java库解包和序列化…


我的bean看起来像这样:
class MyBean {

    private @JsonUnwrapped HashMap map = new HashMap();

    private String name;

    public HashMap getMap() {
        return map;
    }

    public void setMap(HashMap map) {
        this.map = map;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

当我使用以下代码序列化bean时:

MyBean bean = new MyBean();
HashMap map = new HashMap();;
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 documentation.为什么我没有得到解开的结果?