I am sending a GET request to an API. This API requires some sort of compression, gzip in my case. Here is the implementation:
Client
@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
}
ClientConfig
class ClientConfig {
@Bean
fun gzipFeignRequestInterceptor(): RequestInterceptor {
return GzipFeignRequestInterceptor()
}
class GzipFeignRequestInterceptor : RequestInterceptor {
override fun apply(template: RequestTemplate) {
template.header("Accept-Encoding", "gzip")
}
}
}
When i try to call the data()
method I get the following error:
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
I understand the error message but I don't know how to fix it. Is it possible to filter the response before it is further processed?
The request itself shouldn't be a problem, when I try to make the same request in the browser it works fine.
Solved the problem by adding the following properties in my application.yml
feign.compression.response.enabled=true
feign.compression.response.useGzipDecoder=true