简体   繁体   English

如何在 YAML 文件中配置 WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS 用于 Spring Boot 中的 Jackson 反序列化?

[英]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.

相关问题 Spring boot - Jackson 日期序列化和反序列化 - Spring boot - Jackson date serialization and deserialization 如何在 application.yaml/properties 中为 spring.jackson.deserialization.wrap-exceptions=false 配置代码手册 - how configure code manual for spring.jackson.deserialization.wrap-exceptions= false not in application.yaml/properties 如何使用 Spring 和 Jackson 引导在没有纳秒的情况下序列化 Instant? - How to serialize an Instant without nanoseconds using Spring Boot with Jackson? 如何使用YAML文件在Spring Boot中配置Swagger? - How to configure Swagger in Spring Boot using YAML file? 如何使用 Spring Boot 配置 Jackson 转换器? - How to configure Jackson converter with Spring Boot? 如何在 Spring 引导中为 Camel 配置 Jackson ObjectMapper - How to configure Jackson ObjectMapper for Camel in Spring Boot 春季靴子杰克逊与日期 - Spring boot Jackson with Date Jackson将YAML文件反序列化为Map(没有自定义反序列化器) - Jackson deserialization of YAML file into Map (with no custom deserializer) Spring 引导 Jackson 不序列化长时间戳 - Spring Boot Jackson does not serialize timestamps in Long Spring Boot 1.4 自定义内部 Jackson 反序列化 - Spring Boot 1.4 Customize Internal Jackson Deserialization
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM