Spring Boot 2.6.4 所有日期和本地时间类型的变量仅给出数字而没有格式

发布于 2025-01-12 05:29:32 字数 353 浏览 4 评论 0原文

我的 Spring Boot 项目有问题,我从版本 2.5.1 更新到 2.6.4,现在所有变量类型为 date 和 < code>localtime 给出的数字没有格式 示例

date = "2022-03-04" in JSON are "1646352000000"

和我的当地时间是这样的有关

localtime = "09:00:00" in JSON is "9"

如何修复它的任何建议吗?

My spring boot project has a problem, I updated from version 2.5.1 to 2.6.4 and now all my variables of type date and localtime are given number without format
examples :

date = "2022-03-04" in JSON are "1646352000000"

and my localtime are like this :

localtime = "09:00:00" in JSON is "9"

any suggestions on how to fix it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

家住魔仙堡 2025-01-19 05:29:32

您应该配置 Jackson 以避免 Java 日期在时间戳中序列化。

你应该添加

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.5</version>

and configure it like this :

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());

You should configure Jackson in order to avoid serialization of Java dates in timestamp.

You should add

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.5</version>

and configure it like this :

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文