Given a JSON object with an owner's name and an array of pets, how would you map it to a POJO (Plain Old Java Object)?
{ "ownerName": "Robert", "pets": [ { "name": "Kitty" }, { "name": "Rex" }, { "name": "Jake" } ] }
To convert the JSON object into a Java POJO, create two classes: Person and Pet.
public class Person { private String ownerName; private List<Pet> pets; // Getters and Setters } public class Pet { private String name; // Getter and Setter }
In the Person class, ownerName is a string and pets is a list of Pet objects. Each Pet object has a name property. This mapping accurately reflects the structure of the JSON object.
The above is the detailed content of How to Map a JSON Object Array of Pets to a Java POJO?. For more information, please follow other related articles on the PHP Chinese website!