Spring Feign Client JSON parse error: Illegal character

Spring Feign Client JSON parse error: Illegal character

我正在向 API 发送 GET 请求。 API 需要某种压缩,在我的例子中是 gzip。这是实现:

客户端

@FeignClient("client",
        url = "someUrl",
        configuration = [ClientConfig::class])
@RequestMapping(consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
interface Client {
    
    @GetMapping("/data")
    fun data(): CustomResponse
}

客户端配置

class ClientConfig {

    @Bean
    fun gzipFeignRequestInterceptor(): RequestInterceptor {
        return GzipFeignRequestInterceptor()
    }

    class GzipFeignRequestInterceptor : RequestInterceptor {
        override fun apply(template: RequestTemplate) {
            template.header("Accept-Encoding",  "gzip")
        }
    }
}

当我尝试调用 data() 方法时出现以下错误:

feign.codec.DecodeException: Error while extracting response for type [class java.lang.Object] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens

我理解错误信息,但不知道如何解决。是否可以在进一步处理之前过滤响应?

请求本身应该不是问题,当我尝试在浏览器中发出相同的请求时它工作正常。

通过在我的 application.yml

中添加以下属性解决了问题
feign.compression.response.enabled=true
feign.compression.response.useGzipDecoder=true