I want to serialize a LocalDateTime
to textual format while only showing milliseconds. I tried the following example:
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
final LocalDateTime t = LocalDateTime.of(2014, 3, 30, 12, 30, 23, 123456789);
System.out.println(mapper.writeValueAsString(t));
This outputs:
"2014-03-30T12:30:23.123456789"
So the precision is still in nanoseconds, despite to not show them as per mapper.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.
I expected:
"2014-03-30T12:30:23.123"
Why is this? How can I fix this?