错误信息:

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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐