java - @JsonProperty Json object inside Json object -


how use @jsonproperty() json object within json object? example json want is:

"location" : {   "needs_recoding" : false,   "longitude" : "-94.35281245682333",   "latitude" : "35.35363522126198",   "human_address" : "{\"address\":\"7301 rogers ave\",\"city\":\"fort smith\",\"state\":\"ar\",\"zip\":\"\"}" } 

a helpful reference using @jsonproperty annotations in constructor provided staxman. 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 } 

alternately, may deserialize content directly json object tree. illustrated below slight modification of location class example:

public class location {     private boolean needsrecoding;     private double longitude;     private double latitude;      // note use of jsonnode, opposed 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 } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -