微服务bug之:openFeign远程调用返回类型转换异常

 

 

楼主是在使用easyexcel导出的时候,获取数据出现这个错误,因为Spring底层是这样处理的使用LinkedhashMap来承接查询结果,导致转换异常

public List<NeedAllocationEntity> getNeedAllocationData() {

        //查询数据
        Result<PageUtils> result = needAllocationService.list(new HashMap<>(1 << 4));

        //将list取出,获取转换对象的集合
        return result.getData().getList().stream()
                .map(e -> JSON.parseObject(JSON.toJSONString(e), new TypeReference<NeedAllocationEntity>() {
                }))
                .collect(Collectors.toList());
    }
 

解决办法是使用JSON进行转换,先转为string,在转为后面指定的对象

 

posted @ 2022-04-28 17:25  程序员hg  阅读(1406)  评论(0编辑  收藏  举报