调用微服务接口后,对List进行遍历出错。

java.util.LinkedHashMap cannot be cast XXVO

>>>>>>>>>>>>>> java.lang.ClassCastException: java.util.LinkedHashMap cannot be XXVO at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)

 

修改代码,需要将.LinkedHashMap转为Json字符串,然后在转为List。


 BaseResultVo resultVo = consignMainApi.listByNoSet(map.keySet());
           
 List<ConsignMainSimpleVO> simpleVOS1 =  (List<ConsignMainSimpleVO>) resultVo.getData();
           
 List<ConsignMainSimpleVO> simpleVOS = JSONArray.parseArray(JSON.toJSONString(simpleVOS1), ConsignMainSimpleVO.class);
 simpleVOS = simpleVOS.stream().filter(t -> t.getCreateTime().after(DateUtil.parse(dto.getGmtCreateStart()))
                                && t.getCreateTime().before(DateUtil.parse(dto.getGmtCreateEnd()))).collect(Collectors.toList());

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐