spring-boot: spring.jackson.date-format configuration does not affect serialisation of Joda DateTime instances
I have breakpoints set in both:
MappingJackson2HttpMessageConverterConfiguration.mappingJackson2HttpMessageConverter JacksonObjectMapperConfiguration.jacksonObjectMapper
I can see that there is an ObjectMapper bean being created because jacksonObjectMapper is never called and thus MappingJackson2HttpMessageConverterConfiguration uses this other ObjectMapper and not the one that I’m trying to configure. How do I tell what is creating that bean? From that logs, my guess is that it is HypermediaSupportBeanDefinitionRegistrar.registerBeanDefinitions that is doing it from:
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
If I put a breakpoint there it is definitely called before MappingJackson2HttpMessageConverterConfiguration.mappingJackson2HttpMessageConverter but it is so hard to tell if this is the root of my problem. I can’t remove that dependency because it is so pervasively used in my project that it would take me hours to refactor.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 22 (21 by maintainers)
The configuration of
write-dates-as-timestampsworks correctly as far as I can tell, and it affects the serialisation of bothjava.util.Dateandorg.joda.time.DateTimeinstances. The problem is that whenwrite-dates-as-timestampsisfalsespring.jackson.date-formatonly affects the serialisation ofjava.util.Dateinstances.This configuration:
Gives me this output:
Note that both the
java.util.Dateandorg.joda.time.DateTimeinstances have been serialised as timestamps.On the other hand this configuration:
Gives me this output:
Note that both are now being formatted as strings but that only
java.util.Datehas obeyed theDateFormatconfiguration. This is due to the Jackson limitation that I linked to above.I see this behaviour both with and without Spring HATEOAS on the classpath. If you’re seeing behaviour that’s different to what I’ve described above, then please describe your application’s configuration and its dependencies in more detail. Ideally, please provide a sample that shows a
DateTimealways being serialised as a timestamp.@csavory You make a good point about the Spring HATEOAS auto-configuration. Thanks. I’ve opened #2426 to improve the docs.