`WebClient` with default codecs drops `ProblemDetail` extension members
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #37507 by @zsewasdsdsd — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
The gap is in JacksonJsonDecoder under org.springframework.http.codec.json, which unlike JacksonJsonEncoder never registers ProblemDetailJacksonMixin in its default and JsonMapper.Builder constructors. Start by comparing those two classes side by side, then look at the existing codec tests for ProblemDetail decoding to see where a mirror test for the decoder belongs. Done means a WebClient built with default codecs keeps extension members in getProperties(), reproduced with the sample at noojung/webclient-problemdetail-mixin-repro. Note that a PR (#37507) was already opened and closed unmerged, so check the thread before duplicating it.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Java
- Stars
- 60.3k
- Forks
- 38.7k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 36
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-projects/spring-framework
-
status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
spring-projects/spring-framework#37614 ·
Maintainers usually reply within 1 day
-
status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
spring-projects/spring-framework#37613 ·
Maintainers usually reply within 1 day
-
in: core status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
spring-projects/spring-framework#37612 ·
Maintainers usually reply within 1 day
-
`YamlProcessor.getFlattenedMap` with `includeEmpty` returns a `null` key for an empty root mappingMay be free again @erfannvb claimed this 11 days ago, and no pull request is open. Openstatus: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
spring-projects/spring-framework#37522 · 1 comment ·
Maintainers usually reply within 1 day
-
StandardApiVersionDeprecationHandler generates nonconforming Sunset HTTP datesMay be free again A pull request for this issue was closed without being merged. Openstatus: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
spring-projects/spring-framework#37486 · 4 comments ·
Maintainers usually reply within 1 day
All issues in spring-projects/spring-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
build
Difficulty 1/5 Under an hour Newbie friendliness 85/100
MetricsHub/metricshub-community#1472 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsExceptionPossibly taken @jiteshkhatri11 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
javapathfinder/jpf-core#660 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day