[英]How to configure WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS in YAML file for Jackson deserialization in Spring Boot?
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.我从 javascript 应用程序收到一个时间戳作为数字,我的RestController
公开了一个带有 bean 结构和ZonedDateTime
的端点来存储这个值。
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:对 WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS 反序列化功能的InstantDeserializer
class 进行了检查,即使我在 application.yml 中放入以下配置,该值也始终为真:
spring:
jackson:
deserialization:
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS: false
Any ideas?有任何想法吗?
My YAML configuration is not read.我的 YAML 配置未读取。 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:即使我将所有功能都设置为 false,我仍然在 InstantDeserializer 中将 context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS) 测试设为 true:
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
That is a SerializationFeature
not a DeserializationFeature
one, so try the following:那是SerializationFeature
而不是DeserializationFeature
之一,因此请尝试以下操作:
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: (感谢@Arnaud 的提示)鉴于您似乎对反序列化感兴趣,因此可能与检查以下功能相关:
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 .检查参考文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.