Consider this Spring MVC controller started using Spring Boot:
@RequestMapping("/foo")
public Foo get() {
return new Foo();
}
public class Foo {
@Getter
@Setter
private ZonedDateTime time = ZonedDateTime.now();
}
I want to serialize the Foo object with Jackson JSR-310 module. This dependency is on classpath:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
I also have jackson configuration in my application.properties:
spring.jackson.serialization.write-dates-as-timestamps=false
According to jackson documentation it should convert it to ISO datetime format, but I'm still getting a timestamp value...
{
time: 1508867114.796
}
I have noticed that inside ZonedDateTimeSerializer:
@Override
public void serialize(ZonedDateTime value, JsonGenerator generator, SerializerProvider provider) throws IOException {
if (!useTimestamp(provider)) {
if (shouldWriteWithZoneId(provider)) {
// write with zone
generator.writeString(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(value));
return;
}
}
super.serialize(value, generator, provider);
}
useTimestamp(provider)
is evaluated to true
, so the property in application.properties is ignored.
Any ideas what can be wrong with my code?