使用stackoverflow上的代码描述这个问题:
ObjectMapper mapper = new ObjectMapper();
List list = new ArrayList();
try {
list = mapper.readValue(con.getInputStream(), ArrayList.class);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
转换不会出现错误,但是获取具体数据时会抛出异常:
System.out.println(list.get(0));
System.out.println(list.get(0).getForename());
return list;
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.xxx.xxx.web.dto.rp.ConsultantDto异常信息很少。
解决办法:
List myObjects =
mapper.readValue(jsonInput, new TypeReference>(){});
原文:http://blog.csdn.net/wantken/article/details/42643901