Marcel Stör
Marcel Stör

Reputation: 23565

Setting Jackson feature WRITE_DATES_AS_TIMESTAMPS not working in Spring Boot

I set spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false in the Spring Boot config but the Jackson serializer still produces [1942,4,2] instead of "1942-04-02" for a DateTime value.

Some debugging snapshots

Attempts at fixing

Upvotes: 14

Views: 18346

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116311

Spring Boot takes the presence of a WebMvcConfigurationSupport bean as an indication that you want to take complete control of the configuration of Spring MVC. You'd typically end up with such a bean by using @EnableWebMvc but you could also declare your own bean or configuration class that is a WebMvcConfigurationSupport.

If you subclass WebMvcConfigurerAdapter rather than WebMvcConfigurationSupport you're making an additive change to Spring Boot's auto-configuration of Spring MVC rather than taking over completely.

Part of Spring Boot's auto-configuration of Spring MVC is to configure it to use the auto-configured ObjectMapper for HTTP message conversion. If you switch off Boot's auto-configuration of Spring MVC, it will use its own, separate ObjectMapper that is unaffected by any spring.jackson.* configuration settings.

Upvotes: 22

Related Questions