我有一个Object,它有一些属性和一个未知内容的Map。当我序列化它时,我想从Map中展平键值对,使它们显示为MyObject
的属性。下面的代码给出了第一个Json。但我想输出第二个。
{
"MyObject":{
"name":"name",
"id":"id",
"other":{
"key1":"value1",
"key2":"value2"
}
}
}
{
"MyObject":{
"name":"name",
"id":"id",
"key1":"value1",
"key2":"value2"
}
}
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(this);
public class JsonParent {
private TopLevel topLevel;
JsonProperty("MyObject")
public TopLevel getTopLevel() {
return topLevel;
}
}
public class TopLevel {
private String id;
private String name;
private HashMap<String, String> other;
public getId()
public getName()
public getOther()
}