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

Nilotpal
  • 3,237
  • 4
  • 34
  • 56
  • Have you read this? https://stackoverflow.com/questions/42621547/jackson-error-illegal-character-only-regular-white-space-allowed-when-parsi – z atef Aug 27 '20 at 03:45
  • yes. Basically i am getting the issue from webclient. The issue is basically how to resolve the same JSonParseException in webclient. – Nilotpal Aug 27 '20 at 04:01
  • 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" – z atef Aug 27 '20 at 04:03
  • Yes when the endpoint is POSTed in postman, it gives JSON response. – Nilotpal Aug 27 '20 at 04:06
  • Can test if the token is valid using something like this: https://gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7 – z atef Aug 27 '20 at 04:09
  • I dont think it should be much related to Authentication tokens. Its failing after we receive the response, while parsing jSON. – Nilotpal Aug 27 '20 at 04:22

3 Answers3

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.

0

I missed implementing Serializable to the response object.

Nilotpal
  • 3,237
  • 4
  • 34
  • 56
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

Prasanth Rajendran
  • 4,570
  • 2
  • 42
  • 59