Jackson databind InvalidFormatException:无法反序列化 org.threeten.bp.ZonedDateTime

Jackson databind InvalidFormatException : Failed to deserialize org.threeten.bp.ZonedDateTime

提问人:Chathura Wijesinghe 提问时间:12/1/2019 更新时间:12/1/2019 访问量:352

问:

如何修复 forInvalidFormatException2019-12-01T06:16:50.289+0000

Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of
type `org.threeten.bp.ZonedDateTime` from String "2019-12-01T06:16:50.289+0000": Failed to deserialize 
org.threeten.bp.ZonedDateTime: (org.threeten.bp.format.DateTimeParseException) 
Text '2019-12-01T06:16:50.289+0000'

对象映射器配置

  objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
  objectMapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE)
  objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false)
  objectMapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false)
  objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false)

  objectMapper.registerModule(ThreeTenModule())

在下面添加了依赖项

implementation 'com.tinder.scarlet:message-adapter-jackson:0.1.8'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.0'
implementation 'com.fasterxml.jackson.core:jackson-core:2.10.0'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.0'
implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.9'
implementation 'com.github.joschi.jackson:jackson-datatype-threetenbp:2.10.0'

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.4'
implementation 'javax.xml.bind:jaxb-api:2.3.0'
Android Jackson-Databind ThreeTenBP

评论

0赞 Anonymous 12/1/2019
这不是我的主场,但我怀疑杰克逊希望在偏移量中有一个冒号,所以而不是.这至少是 one-arg 所期望的。顺便说一句,由于您的字符串中有一个偏移量并且没有时区(如 ),因此表示它的类会更正确。+00:00+0000ZonedDateTime.parse()Australia/SydneyOffsetDateTime
0赞 Anonymous 12/1/2019
可能相关: 使用 java 将 date 转换为 AEST
0赞 Chathura Wijesinghe 12/2/2019
@OleV.V.时间格式正确。看来我需要为此创建一个杰克逊模块。
0赞 Anonymous 12/2/2019
根据 ISO 8601 标准,冒号是可选的,但 Java 只接受带有冒号的表单。杰克逊似乎也是如此。不好意思。

答: 暂无答案