Search code examples
javajsonencodingjacksonpojo

POJO to Jackson with nested Objects


I want to convert a POJO to JSON (using Jackson-core-asl) of the format:

{"People" : 
[{"age":"1", "height":"5"}, {"age":"2", "height":"4"}] }

When I create the Person object in the POJO (with instance variables age and height), should I define the object as a separate POJO or should I provide a nested definition for the object?


Solution

  • Create your Person POJO with age and height. Create another POJO that will have a List/Set or array of type Person named People. Deserialize your JSON for that type.