本机图像不遵守 @JsonFormat 的日期格式
Native image doesn't respect date format with @JsonFormat
具有以下字段配置
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
当我 运行 带有 java 的项目时,打印日期的结果是:
{"name":"test","date":"2021-11-20 23:12:12"}
但是对于原生图像:
mvn -T 1C package -Dpackaging=native-image -Pgraalvm
执行二进制文件:
./target/jackson-string-error
发送 post:
curl -X POST --location "http://localhost:8080/main" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"name\":\"test\",\"date\":\"2021-11-20 23:12:12\"}"
结果是:
{"name":"test","date":[2021,11,20,23,12,12]}
由于某种原因,日期未被解析。
样本:https://github.com/j1cs/jackson-string-error
OS:Macos Big Sur
Micronaut 版本:3.1.4
Graalvm 版本:21.2.0.r11-grl
问题 github:https://github.com/micronaut-projects/micronaut-core/issues/6546
更新:
我制作了 mi 自己的序列化程序,但仍然无法正常工作。
我添加了一个 log 看它是否通过 class.
当我 运行 带有 java 的应用程序时,它会打印日志:
02:31:46.585 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1171ms. Server Running: http://localhost:8080
02:31:50.729 [default-nioEventLoopGroup-1-2] INFO me.jics.CustomDateSerializer - the formatter: yyyy-MM-dd HH:mm:ss
02:31:50.730 [default-nioEventLoopGroup-1-2] INFO me.jics.MainController - {"date":"2021-11-20 23:12:12","name":"test"}
但是对于原生图像,日志“格式化程序”不打印:
02:30:23.601 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 29ms. Server Running: http://localhost:8080
02:30:28.561 [default-nioEventLoopGroup-1-2] INFO me.jics.MainController - {"name":"test","date":[2021,11,20,23,12,12]}
由 micronaut 框架团队解决:https://github.com/micronaut-projects/micronaut-core/issues/6546
具有以下字段配置
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
当我 运行 带有 java 的项目时,打印日期的结果是:
{"name":"test","date":"2021-11-20 23:12:12"}
但是对于原生图像:
mvn -T 1C package -Dpackaging=native-image -Pgraalvm
执行二进制文件:
./target/jackson-string-error
发送 post:
curl -X POST --location "http://localhost:8080/main" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"name\":\"test\",\"date\":\"2021-11-20 23:12:12\"}"
结果是:
{"name":"test","date":[2021,11,20,23,12,12]}
由于某种原因,日期未被解析。
样本:https://github.com/j1cs/jackson-string-error
OS:Macos Big Sur
Micronaut 版本:3.1.4
Graalvm 版本:21.2.0.r11-grl
问题 github:https://github.com/micronaut-projects/micronaut-core/issues/6546
更新:
我制作了 mi 自己的序列化程序,但仍然无法正常工作。
我添加了一个 log 看它是否通过 class.
当我 运行 带有 java 的应用程序时,它会打印日志:
02:31:46.585 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1171ms. Server Running: http://localhost:8080
02:31:50.729 [default-nioEventLoopGroup-1-2] INFO me.jics.CustomDateSerializer - the formatter: yyyy-MM-dd HH:mm:ss
02:31:50.730 [default-nioEventLoopGroup-1-2] INFO me.jics.MainController - {"date":"2021-11-20 23:12:12","name":"test"}
但是对于原生图像,日志“格式化程序”不打印:
02:30:23.601 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 29ms. Server Running: http://localhost:8080
02:30:28.561 [default-nioEventLoopGroup-1-2] INFO me.jics.MainController - {"name":"test","date":[2021,11,20,23,12,12]}
由 micronaut 框架团队解决:https://github.com/micronaut-projects/micronaut-core/issues/6546