`WebClient` with default codecs drops `ProblemDetail` extension members
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
- #37507 @zsewasdsdsd による — マージされずにクローズ
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 70/100
調査の方向性
ギャップは org.springframework.http.codec.json の JacksonJsonDecoder にあります。JacksonJsonEncoder と異なり、デフォルトコンストラクタと JsonMapper.Builder を受け取るコンストラクタのどちらでも ProblemDetailJacksonMixin を登録していません。まず両クラスを並べて比較し、次に ProblemDetail のデコードに関する既存のコーデックテストを確認して、デコーダー用の対応するテストをどこに置くべきかを見極めてください。デフォルトのコーデックで構成された WebClient が getProperties() の拡張メンバーを保持することが完了条件で、noojung/webclient-problemdetail-mixin-repro のサンプルで再現します。PR (#37507) はすでに開かれ、マージされずにクローズされていることに注意し、重複させる前にスレッドを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Overview
While checking that RestClient and WebClient decode ProblemDetail responses correctly, I noticed that a WebClient created with the default codecs (WebClient.create() or WebClient.builder()) drops RFC 9457 extension members: getProperties() returns null, while the standard members are decoded correctly.
This worked with Spring Framework 6.2 (Spring Boot 3.5), so it looks like a regression introduced with the Jackson 3 codecs.
Versions tested
- Spring Framework 7.0.9 (Spring Boot 4.1.1, Jackson 3): extension members are lost
- Spring Framework 6.2.11 (Spring Boot 3.5.6, Jackson 2): works as expected
Reproducer
With the sample server running on port 8080, GET /orders/42 returns HTTP 404 with Content-Type: application/problem+json and the following body:
{
"type": "https://example.com/problems/order-not-found",
"title": "Order Not Found",
"status": 404,
"detail": "Order 42 does not exist",
"instance": "/orders/42",
"errorCode": "ORDER_NOT_FOUND",
"orderId": 42
}
The extension members are lost when decoding the response:
WebClient webClient = WebClient.create("http://localhost:8080");
// Also reproduces with:
// WebClient.builder().baseUrl("http://localhost:8080").build();
WebClientResponseException.NotFound exception = assertThrows(
WebClientResponseException.NotFound.class,
() -> webClient.get()
.uri("/orders/42")
.retrieve()
.bodyToMono(Order.class)
.block());
ProblemDetail problemDetail = exception.getResponseBodyAs(ProblemDetail.class);
assertThat(problemDetail).isNotNull();
assertThat(problemDetail.getProperties())
.containsEntry("errorCode", "ORDER_NOT_FOUND")
.containsEntry("orderId", 42);
// 6.2.11: passes
// 7.0.9: fails because getProperties() returns null
A complete sample (Spring MVC server + WebClient/RestClient tests) is available here: https://github.com/noojung/webclient-problemdetail-mixin-repro
Running ./gradlew test starts the server automatically and fails webClientCreateShouldPreserveProblemDetailProperties and webClientBuilderShouldPreserveProblemDetailProperties.
For comparison, RestClient.create() and the WebClient.Builder auto-configured by Spring Boot both keep the extension members, since JacksonJsonHttpMessageConverter registers the mixin and Boot configures the codecs with a JsonMapper that has it (spring-projects/spring-boot#47298).
Analysis
JacksonJsonEncoder and JacksonJsonHttpMessageConverter register ProblemDetailJacksonMixin in their default and JsonMapper.Builder-based constructors, but JacksonJsonDecoder does not. Since FAIL_ON_UNKNOWN_PROPERTIES is disabled by default in Jackson 3, the extension members are ignored without any error.
With Jackson 2, the default Jackson2JsonDecoder created its mapper through Jackson2ObjectMapperBuilder, which registers the mixin.
Workaround
WebClient webClient = WebClient.builder()
.codecs(configurer -> configurer.defaultCodecs().jacksonJsonDecoder(new JacksonJsonDecoder(
JsonMapper.builder().addMixIn(ProblemDetail.class, ProblemDetailJacksonMixin.class))))
.build();
Related issues
- #35597
- spring-projects/spring-boot#47298
Would registering ProblemDetailJacksonMixin in the default and JsonMapper.Builder-based constructors of JacksonJsonDecoder, the same way as in JacksonJsonEncoder, be the right fix? If so, I would be happy to submit a pull request.
- 主要言語
- Java
- スター
- 60.3k
- フォーク
- 38.7k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 35
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
spring-projects/spring-framework のほかの issue
-
`YamlProcessor.getFlattenedMap` with `includeEmpty` returns a `null` key for an empty root mapping対応中かも @erfannvb が 6 日前に担当しました。 オープンstatus: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
spring-projects/spring-framework#37522 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
StandardApiVersionDeprecationHandler generates nonconforming Sunset HTTP dates再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンstatus: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
spring-projects/spring-framework#37486 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
FastByteArrayOutputStream input stream rejects valid skip(long) arguments再び着手できるかも @hickey-ai が 9 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンstatus: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
spring-projects/spring-framework#37471 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
LinkedCaseInsensitiveMap.keySet().remove returns false after removing a null-valued entry再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンstatus: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
spring-projects/spring-framework#37470 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
ServerSentEventHttpMessageReader does not recognize data fields without a colon再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンin: web status: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
spring-projects/spring-framework#37461 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
spring-projects/spring-framework の issue をすべて見る
似ている issue
-
pdfium-drift
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
Stirling-Tools/JPDFium#188 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
openremote/openremote#3487 · コメント 1 件 ·
-
Type/Bug U2
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
wso2/product-is#28675 ·
メンテナーはふだん 1 日以内に返信
-
a:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信