简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM