Use the code on StackOverflow to describe the problem:
Objectmapper mapper = new Objectmapper (); list<consultantdto> list = new arraylist<consultantdto> (); try { list = Mapper.readvalue (Con.getinputstream (), arraylist.class); } catch (Jsongenerationexception e) { e.printstacktrace (); } catch (Jsonmappingexception e) { e.printstacktrace (); } catch (IOException e) { e.printstacktrace (); }
The conversion will not have an error, but it will throw an exception when getting the specific data:
System.out.println (list.get (0)); System.out.println (List.get (0). Getforename ()); return list;
<span style= "color: #FF0000;" ><strong>java.lang.classcastexception:java.util.linkedhashmap cannot is cast to Com.xxx.xxx.web.dto.rp.consultantdto</strong></span>
There is very little exception information.
Workaround:
list<consultantdto> myobjects = mapper.readvalue (jsoninput, New typereference<list<consultantdto >> () {});
Jackson conversion Generic list error java.util.LinkedHashMap cannot be cast to com.xxx