在将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]"}
发布评论
评论(1)
您看到这种行为的原因是因为杰克逊是不是用于序列化JSON的原因。
相反,JSON-B正在处理该任务。
Quarkus-JSONB从以下树中包括在内:
您可以使用Quarkus“隐藏”某些类Path Resources的能力之一。
参见细节。
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:
You can use one of Quarkus' ability to "hide" certain classpath resources.
See this for more details.