Override default formatter in JavaTimeModule
See original GitHub issueIs there a way to override the default formatter used in the JavaTimeModule
? Using the @JsonFormat
-annotation works fine, but I would like to setup the formatter where I instantiate my ObjectMapper
.
I know I can simply register my own JsonDeserializer
, but I would prefere to keep using the already existing implementation, so I could still use @JsonFormat
where necessary.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to set format of string for java.time.Instant using ...
One solution is to use jackson-modules-java8. Then you can add a JavaTimeModule to your object mapper:
Read more >Spring Boot: Customize the Jackson ObjectMapper - Baeldung
When using Spring Boot, we have the option to customize the default ObjectMapper or to override it. We'll cover both options in the...
Read more >Formatting Java Time with Spring Boot using JSON - TouK
The aim of this post is to summarize and review ways of formatting Java Time objects using Spring Boot and Jackson library.
Read more >DurationDeserializer should use @JsonFormat.pattern (and ...
When deserializing DurationDeserializer treats all durations of number values as seconds and delegates string values to Duration.parse.
Read more >JavaTimeModule (Jackson datatype: JSR310 2.9.0 API)
Legacy version has the same functionality, but slightly different default ... Period , which always results in an ISO-8601 format because Periods must...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would actually recommend a different mechanism, so-called “Config overrides”, since use of actual (de)serializers directly is actually not part of supported API (it may work, but might not and may break with newer versions).
Usage with 2.x is like so:
The main reason why this is preferred is simply that the mechanism of construction of (de)serializers may change as it is considered part of internal API.
Yes, I can confirm, it’s working fine. My
ObjectMapper
is now using a custom default but still be able to use the@JsonFormat
-Annotations. Thanks for the hint!