I've created a Spring Boot v4.0.0-M3 app that reproduces an issue with the new TestRestClient. To reproduce the issue

This class has two tests

  1. parseResponseAsApiErrorResponse calls an endpoint and parses the response to a ApiErrorResponse
  2. parseResponseAsString calls an endpoint, parses the response body as a String then converts that to an ApiErrorResponse via objectMapper.readValue(responseBody, ApiErrorResponse.class)

The first test fails, but the second one passes, because only the second test calls the custom deserializer ApiErrorResponseDeserializer.

Why is the custom serializer ignored by the first test?

Comment From: wilkinsona

You've created the RestTestClient in your own configuration and haven't configured it to use the JsonMapper from the context. As such, it doesn't know anything about your custom JSON configuration. To get it to work, it would have to be set up with a JacksonJsonHttpMessageConverter that's using the context's JsonMapper.

Built-in support for RestTestClient is coming in 4.0.0-RC1, although I think it may be missing this customisation too. I'll re-open #47335 so that we can double-check.