错误信息:

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"}]

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

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐