A useful link for using @JsonProperty annotations in the constructor is provided by StaxMan . A simple example shown below:
public class Address { private String address; private String city; private String state; private String zip; // Constructors, getters/setters } public class Location { private boolean needsRecoding; private Double longitude; private Double latitude; private Address humanAddress; public Location() { super(); } @JsonCreator public Location( @JsonProperty("needs_recoding") boolean needsRecoding, @JsonProperty("longitude") Double longitude, @JsonProperty("latitude") Double latitude, @JsonProperty("human_address") Address humanAddress) { super(); this.needsRecoding = needsRecoding; this.longitude = longitude; this.latitude = latitude; this.humanAddress = humanAddress; } // getters/setters }
Alternatively, you can deserialize the content directly in the JSON object tree. The following illustrates a small change to the Location class example:
public class Location { private boolean needsRecoding; private Double longitude; private Double latitude; // Note the use of JsonNode, as opposed to an explicitly created POJO private JsonNode humanAddress; public Location() { super(); } @JsonCreator public Location( @JsonProperty("needs_recoding") boolean needsRecoding, @JsonProperty("longitude") Double longitude, @JsonProperty("latitude") Double latitude, @JsonProperty("human_address") JsonNode humanAddress) { super(); this.needsRecoding = needsRecoding; this.longitude = longitude; this.latitude = latitude; this.humanAddress = humanAddress; } // getters/setters }
source share