feign服务中的返回类型

问题描述 投票:0回答:1

您好,我正在使用一个返回字符串(好的)的服务(我无法修改它),并且我无法将它与 FeignClient 一起使用,我收到以下消息:

"statusText": "feign.FeignException: Unrecognized token 'OK': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

这是我正在使用的服务的签名:

@PostMapping(path = "/url", consumes = {MediaType.APPLICATION_JSON_VALUE})
@ApiResponses(value = {
        @ApiResponse(responseCode = "500", description = "Internal server error"),
        @ApiResponse(responseCode = "401", description = "Unauthorized"),
        @ApiResponse(responseCode = "403", description = "Forbidden"),
        @ApiResponse(responseCode = "400", description = "Bad Request"),
        @ApiResponse(responseCode = "200", description = "OK")})
String apiName(@RequestBody ApiDTO apiDTO) throws ResourceException;

我用它作为:

    @PostMapping(path = { "/url" }, consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.TEXT_PLAIN_VALUE})
@ResponseStatus(HttpStatus.OK)
String apiService(@RequestBody myDTO application) throws Exception;

}

我该如何解决?

java spring spring-boot spring-cloud-feign
1个回答
0
投票

我已经解决了这个问题,问题是我正在使用的服务没有正确序列化响应。

为了解决这个问题,我必须创建一个自定义解码器,而不是使用标准解码器。

© www.soinside.com 2019 - 2024. All rights reserved.