当前位置:   article > 正文

关于java.util.LinkedHashMap cannot be cast to ......的解决办法(转化成某实体)_java.util.linkedhashmap cannot be cast to java.uti

java.util.linkedhashmap cannot be cast to java.util.list

 

问题具体描述:接口获取的数据,封装在CXFResponseVo,从该类获取list,遍历list时,需要获取list中的对象,报错

原因:list存储的并不是正常的java实体类,需要将list转成json字符串,再转回list,并且在转回的时候设置格式

  1. String outsourceOrderReport = outsourceTaskInter.getOutsourceOrderReport(jsonmap);
  2. CXFResponseVo cxfResponseVo = null;
  3. if (outsourceOrderReport != null) {
  4. cxfResponseVo = MyJsonUtil.str2obj(outsourceOrderReport, CXFResponseVo.class);
  5. }
  6. List<OutsourcingOrderDetails> resultList= (List<OutsourcingOrderDetails>) cxfResponseVo.getData();

使用jackjson框架

  1. //再次转换list
  2. ObjectMapper objectMapper=new ObjectMapper();
  3. String tranStr = null;
  4. List<OutsourcingOrderDetails> tranList=null;
  5. try {
  6. tranStr = objectMapper.writeValueAsString(resultList);
  7. JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, OutsourcingOrderDetails.class);
  8. tranList= objectMapper.readValue(tranStr, javaType);
  9. } catch (IOException e) {
  10. e.printStackTrace();
  11. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/305352
推荐阅读
相关标签
  

闽ICP备14008679号