【问题标题】:Native image doesn't respect date format with @JsonFormat原生图像不尊重 @JsonFormat 的日期格式
【发布时间】:2021-11-20 16:40:50
【问题描述】:

具有如下字段配置
@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
发帖:
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
操作系统:Macos Big Sur
Micronaut 版本:3.1.4
Graalvm 版本:21.2.0.r11-grl
问题github:https://github.com/micronaut-projects/micronaut-core/issues/6546

更新: 我做了我自己的序列化程序,但仍然无法正常工作。
我添加了一个 log 以查看它是否通过了该课程。
当我使用 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]}

【问题讨论】:

    标签: jackson micronaut graalvm graalvm-native-image


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-31
      • 2021-05-14
      • 2018-02-01
      • 2023-01-05
      • 2020-05-21
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多