Nilotpal
Nilotpal

Reputation: 3588

org.springframework.core.codec.DecodingException: JSON decoding error: Illegal character ((CTRL-CHAR, code 31))

I am getting the following error getting a response of a post method via WebClient(org.springframework.web.reactive.function.client)

org.springframework.core.codec.DecodingException: JSON decoding 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
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 2]
at org.springframework.http.codec.json.AbstractJackson2Decoder.processException(AbstractJackson2Decoder.java:215)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Ȁ

I have tried changing the headers of the request as under with failure :-

headers.put("Accept-Encoding", "gzip");

or

headers.put("Accept-Encoding", "identity");

Is it that webclient is unable to process the gzipped response for any reason!!

Thanks in advance!!

Upvotes: 2

Views: 11924

Answers (3)

Vivek Arora
Vivek Arora

Reputation: 49

Remove header ("Accept-Encoding", "gzip") You will not get JSON decoding error: Illegal character ((CTRL-CHAR, code 31))

If the response length is increased beyond default threshold then response would be gziped and it will give JSON decoding error.

Upvotes: 4

Prasanth Rajendran
Prasanth Rajendran

Reputation: 5512

I have started getting this exception with Spring boot's feign dependency spring-cloud-openfeign-core when I upgrade the version of spring-cloud-openfeign-core to 2.2.5.RELEASE.

For those who upgrade to version 2.2.5.RELEASE or later version will face this issue if they already have the property feign.request.compression=true.

The technical reason behind this is, in FeignContentGzipEncodingAutoConfiguration class the conditional property annotation signature changed from @ConditionalOnProperty("feign.compression.request.enabled", matchIfMissing = false) to @ConditionalOnProperty(value = "feign.compression.request.enabled"), so by default FeignContentGzipEncodingInterceptor is triggered. GitHub reference

Workaround

If your calling a spring-boot service which doesn't have a mechanism to handle the compressed request then disable the feign request compression using the below property

feign.request.compression=false.

NOTE: Unfortunately, we still don't have the out-of-box solution in spring-boot to handle the compressed request refer

Upvotes: 0

Nilotpal
Nilotpal

Reputation: 3588

I missed implementing Serializable to the response object.

Upvotes: 0

Related Questions