I am using RESTEasy to implement a REST Service using JSON serialization. Currently, Dates are getting serialized to milliseconds since 1970. To improve compatibility, I would
Using with the JSR310 (new api date) - LocalDate, LocalDateTime, LocalTime
Add dependence:
com.fasterxml.jackson.datatype
jackson-datatype-jsr310
2.4.0
And create a provider to register the module:
@Provider
public class JacksonConfig implements ContextResolver {
private final ObjectMapper objectMapper;
public JacksonConfig() throws Exception {
objectMapper = new ObjectMapper()
.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS )
.disable( SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS )
.setSerializationInclusion( JsonInclude.Include.NON_NULL )
.registerModule( new JSR310Module() );
}
@Override
public ObjectMapper getContext( Class> arg0 ) {
return objectMapper;
} }