我有这样的豆子
class Foo {
private Map<String, Data> dataMap;
private String fooFieldOne;
private String fooFieldTwo;
}
class Data {
private fieldOne;
private fieldTwo;
}
我想像这样序列化为Json
{
"key1": {
"fieldOne": "some value",
"fieldTwo": "some value"
},
"key2": {
"fieldOne": "some other value",
"fieldTwo": "some other value"
},
"fooFieldOne":"valueone",
"fooFieldTwo":"valuetwo"
}
但我得到的结果像
{
"dataMap": {
"key1": {
"fieldOne": "some value",
"fieldTwo": "some value"
},
"key2": {
"fieldOne": "some other value",
"fieldTwo": "some other value"
}
},
"fooFieldOne":"valueone",
"fooFieldTwo":"valuetwo"
}
如何忽略上述json中的dataMap层?我为此使用了 java jackson 库。
我试过的代码是
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(myFOOObject)