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
In
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.Jackson2ObjectMapperBuilderCustomizerConfiguration.StandardJackson2ObjectMapperBuilderCustomizer#customizethere'sconfigureFeatures(builder, this.jacksonProperties.getSerialization());which shows that "WRITE_DATES_AS_TIMESTAMPS" -> "false"
Then a bit later in
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder#configurethere's this loopfor (Object feature : this.features.keySet()) { configureFeature(objectMapper, feature, this.features.get(feature)); }and again
this.featuressays "WRITE_DATES_AS_TIMESTAMPS" -> "false"Yet during serialzation of a
DateTimecom.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase#useTimestampsays false becauseprovider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)returns false.
Attempts at fixing
- Out of despair I replaced
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=falsewithspring.jackson.serialization.write-dates-as-timestamps=falsebecause I found that mentioned in a lot of places (even though the Boot documentation doesn't hint at this). What about this? They seem to be synonyms - no effect. - While writing this question SO suggested WRITE_DATES_AS_TIMESTAMPS not woking on Spring boot 1.3.5. The answer says to replace
WebMvcConfigurationSupportwithWebMvcConfigurerAdapter. While this does help indeed I fail to understand why so.