org.springframework.core.codec.DecodingException:JSONデコードエラー:不正な文字((CTRL-CHAR、コード31))
WebClient(org.springframework.web.reactive.function.client)を介してpostメソッドの応答を取得すると次のエラーが発生します
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: Ȁ
リクエストのヘッダーを以下のように変更しようとしましたが失敗しました:-
headers.put("Accept-Encoding", "gzip");
または
headers.put("Accept-Encoding", "identity");
webclientが何らかの理由でgzip圧縮された応答を処理できないということですか?
前もって感謝します!!
回答
応答オブジェクトにSerializableを実装できませんでした。
spring-cloud-openfeign-coreのバージョンをにアップグレードすると、Springbootの偽の依存関係でこの例外が発生し始めspring-cloud-openfeign-coreました2.2.5.RELEASE。
バージョン2.2.5.RELEASE以降のバージョンにアップグレードする場合、既にプロパティを持っていると、この問題が発生しますfeign.request.compression=true。
この背後にある技術的な理由は、
FeignContentGzipEncodingAutoConfigurationクラスで条件付きプロパティアノテーションシグネチャがから@ConditionalOnProperty("feign.compression.request.enabled", matchIfMissing = false)に変更された@ConditionalOnProperty(value = "feign.compression.request.enabled")ため、デフォルトFeignContentGzipEncodingInterceptorでトリガーされるためです。GitHubリファレンス
回避策
処理するメカニズムがないcompressed requestSpring -Bootサービスを呼び出す場合は、以下のプロパティを使用して偽のリクエストの圧縮を無効にします
feign.request.compression=false.
注:残念ながら、我々はまだ圧縮されたリクエストを処理するために、スプリングブーツでアウトオブボックスソリューションを持っていない参照してください。