In my Spring Boot application I'm making use of the reactive WebFlux WebClient to retrieve streaming JSON data from an SSE (Server-Sent Events) endpoint. Modifying the default auto-configured Jackson ObjectMapper behavior by setting config options in Spring Boot like spring.jackson.deserialization.read-date-timestamps-as-nanoseconds=false
as suggested by the official docs has no effect on the WebFlux WebClient. I also tried other suggestions outlined in this SO thread like creating custom beans for WebFlux configuration but they did not help, the config is still not being picked up.

- 505
- 6
- 18
3 Answers
After quite some time spent debugging Spring WebFlux / Jackson library code, I was able to finally find a hint to solve the issue looking at the reactive WebFlux WebClient docs. There is some custom plumbing required to make WebClient use the default auto-configured Jackson ObjectMapper. The solution is to configure the default decoder used for processing Server-Sent Events when creating new instance of the WebClient. Here is the sample code:
@Component
public class MarketDataFetcher implements CommandLineRunner {
// ...
private final WebClient webClient;
public MarketDataFetcher(ObjectMapper objectMapper) {
webClient = createWebClient(objectMapper);
}
private WebClient createWebClient(ObjectMapper objectMapper) {
return WebClient.builder()
.codecs(configurer -> configurer.defaultCodecs()
.serverSentEventDecoder(new Jackson2JsonDecoder(objectMapper)))
.baseUrl(BASE_URL)
.build();
}
}
ObjectMapper
is automatically injected by Spring, so no @Autowired
annotation is needed.
It would certainly help if this could be made more explicit in the official documentation somehow. Hope this answer can be useful for someone facing similar issue!

- 505
- 6
- 18
-
1Similar question has been asked on this matter -> https://stackoverflow.com/q/43769301/11251146 – Nipuna Saranga Feb 23 '20 at 12:38
I found in Spring Boot docs that:
the client instance is built using the WebClient.Builder bean auto-configured by Spring Boot
There is also section dedicated to WebClient customization which says:
To make the scope of any customizations as narrow as possible, inject the auto-configured WebClient.Builder and then call its methods as required.
Therefore simplest way to use configured ObjectMapper
is to define WebClient
bean like this:
@Bean
public WebClient webClient(WebClient.Builder builder) {
return builder.build();
}
That is pretty unconvenient that Spring Boot doesn't do that by default given how any other stuff is already configured to use out of box but it is much better than configuring codecs by hand.

- 162
- 4
- 9
I haven't tried the high-level property settings mentioned in the question, but you can surgically configure the Jackson ObjectMapper
at the application level using Jackson2ObjectMapperBuilderCustomizer
, as I explained in my answer to another question.
@Configuration
public class MyAppConfiguration {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonJsonCustomizer() {
return builder -> builder.modulesToInstall(/*TODO specify modules here);
}
}
In limited testing WebFlux seems to use this configuration, e.g. with .bodyToMono(SomeType.class)
.

- 18,219
- 30
- 144
- 272