gpt4 book ai didi

java - 如何阻止 jackson 在反序列化时更改日期时间

转载 作者:行者123 更新时间:2023-11-30 06:05:23 49 4
gpt4 key购买 nike

我正在尝试通过对我的 Spring Boot 应用程序的 get 请求来检索带有日期字段的对象。数据库中的日期是正确的,调试时也是正确的,但当 Jackson 反序列化它们时,日期会改变 1 小时。

上课

@JsonFormat(pattern = "dd-MM-yyyy HH:mm")
private Date matchDate;

在application.properties中

spring.jackson.deserialization.adjust-dates-to-context-time-zone=false

我不知道为什么它会改变它们,我希望 jackson 完全按照原样反序列化日期

最佳答案

该设置的文档说,

"If enabled, contextual TimeZone will essentially override any other TimeZone information; if disabled, it will only be used if value itself does not contain any TimeZone information."

因此,由于您的序列化格式不指示时区,因此该设置不会影响您的反序列化。

我的建议是,如果可能的话,在传递序列化日期时始终包含时区 - 这样,就不存在如何解释该值的问题。

关于java - 如何阻止 jackson 在反序列化时更改日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51443548/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com