I receive a timestamp as a number from a javascript application and my RestController
exposes an endpoint with a bean structure and a ZonedDateTime
to store this value.
There is a check into the InstantDeserializer
class for the WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS DeserializationFeature, and the value is always true even if I put the following configuration in my application.yml:
spring:
jackson:
deserialization:
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS: false
Any ideas?
CodePudding user response:
That is a SerializationFeature
not a DeserializationFeature
one, so try the following:
spring:
jackson:
serialization:
write-date-timestamps-as-nanoseconds: false
Check the reference documentation.
(Thanks @Arnaud for the hint) Given that you seem to be interested in deserialization it might instead be relevant to check the following feature:
spring:
jackson:
deserialization:
read-date-timestamps-as-nanoseconds: false
You can also configure it using a Configuration file:
@Configuration
public class JacksonConfiguration {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper()
.disable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
}
}
Check the reference documentation.
CodePudding user response:
My YAML configuration is not read. Even if I put all the features to false, I still get the context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS) test to true in InstantDeserializer :
spring:
jackson:
serialization:
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS: false
READ_DATE_TIMESTAMPS_AS_NANOSECONDS: false
deserialization:
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS: false
READ_DATE_TIMESTAMPS_AS_NANOSECONDS: false