java - 时间戳反序列化失败并显示“无法将'java.lang.String'类型的值转换为所需的'java.time.Instant'类型”
问题描述
我希望有人能指出我在这里缺少的东西。
我有一个带有休息控制器的 Spring Boot 2 应用程序,它接受一些请求参数,其中一个是 java.time.Instant 作为“@RequestParam("offset") Instant offset”。我希望这可以从基于秒或毫秒的时间戳中反序列化,例如 1604303073000。
然而我总是得到提到的异常,起源于 org.springframework.format.datetime.standard.InstantFormatter.parse(InstantFormatter.java:50) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
将 Instant 序列化为基于秒或毫秒的时间戳可以很好地使用这些参数:
jackson:
serialization:
write-dates-as-timestamps: true
write-date-timestamps-as-nanoseconds: true
deserialization:
read-date-timestamps-as-nanoseconds: false
但相反的方式似乎对反序列化完全没有影响,无论它设置为真还是假。Spring 显然只是试图将我的时间戳应用于错误的格式化程序。
我能找到的所有类似问题似乎都暗示这是一个不费吹灰之力的默认行为,但这已经导致了一些令人沮丧的数小时的反复试验。
解决方案
推荐阅读
- c# - 无法使用 Serilog.Sinks.Http nuget 包在 appsettings 中为 serilog 指定 Http 接收器
- ios - TypeError:网络请求失败。React Native、Fetch API、iOS 模拟器
- java - 如何从左下角开始以螺旋形式打印字母?
- python - 在熊猫中绘制一列的前十个值
- html - 如何使用 Bootstrap 使容器在电话设备中占据全宽
- c# - 两个 WebServiceHost 实例
- ruby-on-rails - ArgumentError SMTP To address 不能为空
- python - 如何使用带有 pycharm 和 python 的矩阵创建图像?
- python - 使用 int(.) 去除小数
- python - 如何跳出 While True 循环并返回循环