Jackson-映射OffsetDateTime

时间:2019-04-16 12:55:16

标签: jackson mapping java-time

我在json对象中有一个字符串字段,该字符串字段以以下格式表示日期:2019-04-09T16:29:25Z当然用双引号引起来。

pratica.put(“ dataCreazionePratica”,OffsetDateTime.parse(“ 2019-04-09T16:29:25Z”));

然后,我使用Jackson ObjectMapper将JSON映射到一个对象,该日期为OffsetDateTime对象。我收到以下错误:

Cannot construct instance of `java.time.OffsetDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-04-09T16:29:25Z')

我不理解为什么在错误消息中我得到了单引号。我试图像这样更改json对象:

pratica.put(“ dataCreazionePratica”,OffsetDateTime.parse(“ 2019-04-09T16:29:25Z”));

但随后出现以下错误:

Cannot construct instance of `java.time.OffsetDateTime` (no Creators, like default construct, exist): no int/Int-argument constructor/factory method to deserialize from Number value (2019)

就好像它试图将其读取为整数一样……是否还有其他方法可以解析字符串日期并获取OffsetDateTime?

0 个答案:

没有答案