鉴于简单POJO:
public class SimplePojo {
private String key ;
private String value ;
private int thing1 ;
private boolean thing2;
public String getKey() {
return key;
}
...
}
我没有问题序列化成这样的东西(使用Jackson):
{
"key": "theKey",
"value": "theValue",
"thing1": 123,
"thing2": true
}
但真正让我高兴的是,如果我可以这样序列化该对象:
{
"theKey" {
"value": "theValue",
"thing1": 123,
"thing2": true
}
}
我在想我需要一个自定义序列化器,但我面临的挑战是插入一个新字典,例如:
@Override
public void serialize(SimplePojo value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
gen.writeNumberField(value.getKey(), << Here be a new object with the remaining three properties >> );
}
有什么建议么?
慕哥6287543
慕码人2483693
相关分类