Reputation: 605
Hi I have some JSON which is wrapped as so:
{
rootNode: [{
"property":"value"
}]
}
Is there a way of getting the object in the array as:
@JsonRootName("rootNode")
public class ThisClass{
private String property;
}
If there is no array I can just use the rootnode notation are there any other annotations to compensate for the wrapped array?
Upvotes: 5
Views: 7846
Reputation: 605
Was able to get this working by setting some options on ObjectMapper
mapper
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true),
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
Upvotes: 2
Reputation: 22224
You can parse this JSON by enabling the following deserialization options in jackson:
ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
Check the docs for details
Upvotes: 6