Disabling WRITE_DATES_AS_TIMESTAMPS not working?
See original GitHub issueAccording to the /datetime/ summary, java.time.offsetDateTime objects should serialize out to ISO-8601 strings simply by disabling the SerializationFeature#WRITE_DATES_AS_TIMESTAMPS feature?
I’ve tried to do this in two different ways in the JacksonConfig class:
ObjectMapper mapper = new ObjectMapper()
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return objectMapper;
}
In both cases, serialized offsetDateTime objects continue to be printed in nanosecond timestamp format (i.e. “expiresOn”:1486138656.853000000).
Only by actually declaring @JsonFormat can I get them to print out in ISO-8601 string.
Is anyone else having this issue?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:10 (2 by maintainers)
Top Results From Across the Web
json - Jackson SerializationFeature ...
I'm not sure if there is an easier way to access the Jackson MVC message converter and configure ... WRITE_DATES_AS_TIMESTAMPS is disabled.
Read more >Date is always serialised as long | by Valery Yakovlev - Medium
I tried to temporarily remove this configuration and run the app. The dates were serialised properly in the ISO standard, as expected.
Read more >Jackson Date - Baeldung
This problem occurs because JSON doesn't natively have a date format, so it represents dates as String. The String representation of a date...
Read more >SerializationFeature (jackson-databind 2.6.0 API) - FasterXML
Feature that determines whether Date s (and sub-types) used as Map keys are serialized as timestamps or not (if not, will be serialized...
Read more >Jackson and SerializationFeature ...
Hi,. is there a deeper reason why the SerializationFeature WRITE_DATES_AS_TIMESTAMPS is not disabled by default? Currently, a LocalDate is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
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
If you are using swagger with spring boot and your date is Date is always getting serialised as long, and SerializationFeature.WRITE_DATES_AS_TIMESTAMPS & spring.jackson.serialization.write-dates-as-timestamps=false are not helping, below solution worked for me. Add it to your class annotated with @SpringBootApplication:
Actual issue: SerializationFeature.WRITE_DATES_AS_TIMESTAMPS value is not read from spring configuration file which need to be set false in order to covert long value while serialisation.
Where do you put this in your code?
ObjectMapper mapper = new ObjectMapper() .registerModule(new ParameterNamesModule()) .registerModule(new Jdk8Module()) .registerModule(new JavaTimeModule()) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
Thanks!