With the latest 4.0.0-SNAPSHOT (4.0.0-20251009.094940-602), with the new spring-boot-test modules, the auto-configured JsonMapper
is not used by WebTestClient
and RestTestClient
.
In contrast, JacksonTester
does use it.
Reproducer: demo6.zip
As a proof of concept, the reproducer defines a property spring.jackson.deserialization.fail-on-null-for-primitives=false
to have Jackson deserialize null
values to the target primitive's default value (0
, false
).
A controller method returns
{"primitive": null}
and a test uses the test clients to deserialize that into a record ResponseDto(int primitive){}
, expecting to get new ResponseDto(0)
.
Instead, Jackson throws Cannot map `null` into type `int` (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)
, suggesting that my property wasn't applied.
When using the auto-configured JacksonTester
to deserialize the response JSON, it works as expected.
Comment From: wilkinsona
Thanks for trying the snapshots. This is, in part at least, a duplicate of #47335. I think the WebTestClient
side of things may be addressed by some other changes that we're working on at the moment as well. We'll keep this open, though, as a reminder to check that this is indeed the case.
Comment From: wilkinsona
This has been addressed by https://github.com/spring-projects/spring-boot/commit/9eb05ebb102b17e9680706169d36aa52b7e8ac73 as part of https://github.com/spring-projects/spring-boot/issues/46356.
Comment From: kzander91
@wilkinsona The latest snapshots fixed the issue for RestTestClient
, but not for WebTestClient
.
I have updated my demo project to declare the (apparently) now-required @AutoConfigureWebTestClient
and @AutoConfigureRestTestClient
annotations and still get the same failure for the webTestClient()
test: demo6.zip
Side note: Is it intentional that @WebMvcTest
and @WebFluxTest
are no longer auto-configuring test clients?