Spring Feign Client JSON ошибка синтаксического анализа: недопустимый символ - PullRequest
0 голосов
/ 09 июля 2020

Я отправляю запрос GET в API. Для этого 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
}

ClientConfig

class ClientConfig {

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

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

Когда я пытаюсь вызвать data() method Я получаю следующую ошибку:

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

Я понимаю сообщение об ошибке, но не знаю, как ее исправить. Можно ли отфильтровать ответ перед его дальнейшей обработкой?

Сам запрос не должен быть проблемой, когда я пытаюсь сделать тот же запрос в браузере, он работает нормально.

1 Ответ

0 голосов
/ 10 июля 2020

Решил проблему, добавив следующие свойства в мой application.yml

feign.compression.response.enabled=true
feign.compression.response.useGzipDecoder=true
...