如何使用jackson在java中解开和序列化java映射?
我有一个这样的豆子
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中的数据映射层?我正在使用java jackson库来实现这一点。
我尝试的代码是
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(myFOOObject)