-
Notifications
You must be signed in to change notification settings - Fork 0
ISO 8601 Timestamps with Jackson
Dan edited this page Sep 23, 2016
·
1 revision
By default the mapper serializes Dates as a numeric values. To get ISO-8601 formats use JavaTimeModule
and set SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
... Note the following configuration supports Durations too!
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JavaTimeModule());
example output:
2016-09-22T17:46:40.919+0000
reference
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.2</version>
</dependency>
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;