Given the simple POJO
:
public class SimplePojo {
private String key ;
private String value ;
private int thing1 ;
private boolean thing2;
public String getKey() {
return key;
}
...
}
I have no issue in serializing into something like so (using Jackson
):
{
"key": "theKey",
"value": "theValue",
"thing1": 123,
"thing2": true
}
but what would really make me happy is if I could serialize that object as such:
{
"theKey" {
"value": "theValue",
"thing1": 123,
"thing2": true
}
}
I'm thinking I would need a custom serializer, but where I'm challenged is in inserting a new dictionary, e.g.:
@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 >> );
}
Any suggestions?