Quarkus应用程序的reteasy休息响应忽略Jackson config Quarkus.jackson.write-dates-as as-timestamps = true

发布于 2025-01-28 23:22:33 字数 933 浏览 3 评论 0 原文

在将Java应用程序迁移到Quarkus的过程中,我们遇到了包括Java.util.date对象在内的重新响应,正在转换为日期字符串,而不是以毫秒为单位的长度戳记。

根据Quarkus文档,此默认行为是正常的,可以通过将 quarkus.jackson.write-dates-dates-as-astimestamps = true 放在应用程序中。结果是保持字符串日期,而不是时间戳,无论将其设置为 true 。 我们还尝试通过 ObjectMapperCustomizer 明确地设置此配置属性,但这也无法解决。

Quarkus版本:2.9.0

任何想法我们如何强制时间戳进行任何重新响应?

受影响的代码: https://github.com/labsai/eddi/eddi

edit 编辑: 我添加了一个reteasy端点,其中包含一个更容易复制该问题的日期的测试响应:

使用 ./ mvnw compile Quarkus:dev (需要启用docker,否则您需要一个mongodb启动并运行)

然后获取http:// localhost:7070/test ,它导致 {“ date”:“ 2022-05-- 16T07:49:13.001Z [UTC]“}

in the process of migrating a java app to quarkus, we have encountered that resteasy responses which include a java.util.Date object, are being converted to a Date String instead of a long timestamp in milliseconds.

According to the quarkus documentation, this default behavior is normal and can be disabled by putting quarkus.jackson.write-dates-as-timestamps=true in the application.properties file, but it seems to be ignored as the result stays a string date instead of a timestamp regardless of this config being set to true.
We also tried to set this config property explicitly via an ObjectMapperCustomizer, but that didn't work out either.

Quarkus version: 2.9.0

Any ideas how we can force timestamps for any resteasy response?

Affected Code: https://github.com/labsai/EDDI

EDIT:
I have added a resteasy endpoint with a test response containing a date to more easily reproduce the issue:
https://github.com/labsai/EDDI/blob/master/src/main/java/ai/labs/eddi/configs/Test.java

Start app with ./mvnw compile quarkus:dev (docker needs to be enabled, otherwise you need a mongodb up and running)

Then GET http://localhost:7070/test which results in {"date":"2022-05-16T07:49:13.001Z[UTC]"}

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

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

发布评论

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

评论(1

习惯成性 2025-02-04 23:22:33

您看到这种行为的原因是因为杰克逊是不是用于序列化JSON的原因。
相反,JSON-B正在处理该任务。

Quarkus-JSONB从以下树中包括在内:

[INFO] ├─ io.quarkiverse.microprofile:quarkus-microprofile-deployment:jar:2.7.2.Final (compile)
[INFO] │  ├─ io.quarkiverse.microprofile:quarkus-microprofile:jar:2.7.2.Final (compile)
[INFO] │  │  ├─ io.quarkus:quarkus-resteasy-jsonb:jar:2.9.0.Final (compile)
[INFO] │  │  │  ├─ io.quarkus:quarkus-jsonb:jar:2.9.0.Final (compile)

您可以使用Quarkus“隐藏”某些类Path Resources的能力之一。

quarkus.class-loading.removed-resources."org.jboss.resteasy\:resteasy-json-binding-provider"=org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.class

参见细节。

The reason you are seeing this behavior is because Jackson is not being used to serialize JSON.
Instead, JSON-B is handling that task.

quarkus-jsonb is getting included from the following tree:

[INFO] ├─ io.quarkiverse.microprofile:quarkus-microprofile-deployment:jar:2.7.2.Final (compile)
[INFO] │  ├─ io.quarkiverse.microprofile:quarkus-microprofile:jar:2.7.2.Final (compile)
[INFO] │  │  ├─ io.quarkus:quarkus-resteasy-jsonb:jar:2.9.0.Final (compile)
[INFO] │  │  │  ├─ io.quarkus:quarkus-jsonb:jar:2.9.0.Final (compile)

You can use one of Quarkus' ability to "hide" certain classpath resources.

quarkus.class-loading.removed-resources."org.jboss.resteasy\:resteasy-json-binding-provider"=org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.class

See this for more details.

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