I need to wrap my json objects to look like this:
{
"user" : { "id":1 }
}
instead of
{
"id":1
}
So I set:
mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
The serialization part is working fine:
mapper.writeValue(writer, user);
But if I do:
User u = mapper.readValue(writer.toString(), User.class);
The returned object contains only null fields. Do I need to configure something else for reading wrapped elements?
Regards
I think you’re looking for the deserialization configuration counterpart to
SerializationConfig.Feature.WRAP_ROOT_VALUE. It’sDeserializationConfig.Feature.UNWRAP_ROOT_VALUE. (With Jackson 2+, it’sDeserializationFeature.UNWRAP_ROOT_VALUE.)