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

3

1

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!!

Cymoid answered 27/8, 2020 at 3:29 Comment(6)
Have you read this? #42622047Weisler
yes. Basically i am getting the issue from webclient. The issue is basically how to resolve the same JSonParseException in webclient.Cymoid
Can you parse the payload manually? set a debugger or inspect what the client is sending and try to parse it. also try sending the same post request using a different client "postman, curl..etc"Weisler
Yes when the endpoint is POSTed in postman, it gives JSON response.Cymoid
Can test if the token is valid using something like this: gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7Weisler
I dont think it should be much related to Authentication tokens. Its failing after we receive the response, while parsing jSON.Cymoid
M
4

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.

Marseillaise answered 22/4, 2021 at 4:3 Comment(0)
C
0

I missed implementing Serializable to the response object.

Cymoid answered 28/8, 2020 at 2:48 Comment(1)
I see where the issue is.Weisler
H
0

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

Hidie answered 12/11, 2020 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.