gpt4 book ai didi

java - JodaTime 序列化问题

转载 作者:行者123 更新时间:2023-11-30 10:16:17 24 4
gpt4 key购买 nike

我有一个使用 Java JodaTime 的现有应用程序。但是,在升级到最新的 json4s-core 库 3.6.0-M3 之后,将带有时区的日期字符串转换为日期时出现以下错误。

Caused by: java.lang.IllegalArgumentException: No instant converter found for type: org.json4s.ext.DateParser$ZonedInstant

当我编写一个带有多种格式回退的自定义 DateTime 序列化程序时会发生这种情况:

 case JString(s) ⇒ Try(dateTimeFormat.parseDateTime(s)).getOrElse(new DateTime(DateParser.parse(s, format)))

导致问题的示例字符串:2018-05-02T21:43:29Z

我确定我使用的是 jodatime 2.9.2 和匹配的 json4s-ext 库

最佳答案

如果有人遇到类似问题,我会留下我的答案。我意识到,由于我正在覆盖默认的 DateTime 序列化程序,因此我需要对我的自定义序列化程序进行以下更改以处理 ZonedInstant

case JString(s) ⇒ Try(dateTimeFormat.parseDateTime(s)).getOrElse({
val zonedInstant = DateParser.parse(s, format)
new DateTime(zonedInstant.instant, DateTimeZone.forTimeZone(zonedInstant.timezone))
})

关于java - JodaTime 序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50143982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com