openfeign远程调用接口报错:feign.codec.DecodeException: Error while extracting response for type

错误信息:

feign.codec.DecodeException: Error while extracting response for type [java.util.List<xxxx.xxxx..UserComponentRes>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.ArrayList<xxxx.xxxx..UserComponentRes>` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList<xxxx.xxxx..UserComponentRes>` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: (ByteArrayInputStream); line: 1, column: 1]

通过openfeign日志可用看到调用的返回结果如下:

{"data":[{"count":10,"userLevel":"1"},{"count":4,"userLevel":"2"},{"count":4,"userLevel":"3"},{"count":1,"userLevel":"4"}],"errcode":"0","errmsg":"ok","version":"1"}

在这里插入图片描述
这样的返回结果是我们自己使用ApiResult结果集封装的,所以报错。

修改前:

    @PostMapping("/userComponent")
    public ApiResult<List<UserComponentRes>> userComponent(){
        List<UserComponentRes> userComponent = userDetailService.getUserComponent();
        return ApiResult.successMsg(userComponent,"1");
    }

修改后:

    @PostMapping("/userComponent")
    private List<UserComponentRes> userComponent(){
        List<UserComponentRes> userComponent = userDetailService.getUserComponent();
        return userComponent;
    }

删除ApiResult封装后返回的结果如下:

 [{"count":10,"userLevel":"1"},{"count":4,"userLevel":"2"},{"count":4,"userLevel":"3"},{"count":1,"userLevel":"4"}]

这样就可以正常的被我们调用了。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值