java - Map JSON to pojo using Jackson for List that have different parameters -


json format:

[ {     "0":     {         "cast":"",         "showname":"woh pagle",         "type":"episodes"     },     "video":[         {             "src":"video.mp4"         },         {             "drm":"false"         }     ] } ] 

here problem getting below exception:

org.codehaus.jackson.map.jsonmappingexception: can not deserialize instance of java.util.arraylist out of start_object token @ [source: java.io.stringreader@1c9ca1; line: 1, column: 55617] (through reference chain: com.apalya.myplex.valueobject.thirdpartycontentdetailsarray["video"])

my pojo classes :

@jsonignoreproperties(ignoreunknown = true) @jsonproperty("0") private thirdpartysubcontentdetails subcontent;  @jsonproperty("video") private list<thirdpartysubcontentvideoinfo> video; 

my sub class pojo :

private string src;  @jsonignore @jsonproperty("drm") private string drm; 

please me write pojo video list.

your json starts array , not object. important part change how objectmapper should generate json. returning list need way:

list<firstjson> jsonlist = mapper.readvalue(json, new typereference<list<firstjson>>(){}); 

here short working test implement locally:

public static void main(string[] args) {     string json = "[{\"0\":{\"cast\":\"\",\"showname\":\"wohpagle\",\"type\":\"episodes\"},\"video\":[{\"src\":\"video.mp4\"},{\"drm\":\"false\"}]}]";     objectmapper mapper = new objectmapper();      list<firstjson> jsonlist = mapper.readvalue(json, new typereference<list<firstjson>>(){});     system.out.println(jsonlist.tostring()); } 

the first part of jsonarray in pojo.(named firstjson)

public class firstjson{          @jsonproperty("0")         private firstjson subcontent;          private string cast;         private string showname;         private string type;          @jsonproperty("video")         private list<video> videos;        //getter/setter 

and video pojo:

public class video {          private string src;          @jsonproperty("drm")         private string drm;        //getter/setter 

just sidenote: if declare pojos in same class file, classes should static. public static class firstjson


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -