java - Jackson JsonMappingException START_ARRAY error - when json having nested same node -


i trying deserialize below json. json contains same node nested 2 times. can see same image node repeated twice.

{     "error": null,     "feed": [         {             "id": "4",             "message": "hello world!",             "image": {                 "url": "http://localhost:8888/hello/media/55ebe591ee42d.jpg",                 "width": "970",                 "height": "485"             }             "created_at": "2015-09-06 12:34:50",             "updated_at": "0000-00-00 00:00:00",             "profile": {                 "id": "10",                 "name": "mr x",                 "image": {                     "url": "http://localhost:8888/instagram-rest/uploads/profile/55ffa473a1853.jpg",                     "width": "640",                     "height": "640"                 }             }         }     ] } 

below classes required deserialize json.

image.java

public class image {     private string url;     int width, height;      public image() {     }      public image(string url, int width, int height) {         this.url = url;         this.width = width;         this.height = height;     }     /** setter/getters **/ } 

profile.java

public class profile {      private string id;     private string name;      @jsonproperty("image")     private image image;       /** setter/getters **/ } 

feed.java

public class feed {      @jsonignore     private string id;      private string message, created_at, updated_at;      @jsonproperty("id")     private string feed_id;      private int comments_count, likes_count;      @jsonproperty("image")     private image image;      @jsonproperty("profile")     private profile profile;      /** setter/getters **/     } 

feedresponse.java

public class feedresponse extends baseresponse {     @jsonproperty("feed")     private list<feed> feed;      public list<feed> getfeed() {         return feed;     }      public void setfeed(list<feed> feed) {         this.feed = feed;     } } 

and parse json used below code

objectmapper objectmapper = new objectmapper(); feedresponse res = objectmapper.readvalue(response, feedresponse.class); 

while parsing if remove image profile.java working fine. otherwise getting below error.

com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of model.image out of start_array token 

any appreciate.

thank you


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -