Reputation: 4156
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
Upvotes: 1
Views: 2057
Reputation: 67003
I think you're looking for the deserialization configuration counterpart to SerializationConfig.Feature.WRAP_ROOT_VALUE
. It's DeserializationConfig.Feature.UNWRAP_ROOT_VALUE
. (With Jackson 2+, it's DeserializationFeature.UNWRAP_ROOT_VALUE
.)
Upvotes: 2