1

How to fixe the InvalidFormatException for 2019-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'

Object mapper configurations

  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())

Added below dependancies

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'
Chathura Wijesinghe
  • 3,310
  • 3
  • 25
  • 41
  • It’s not my home field, but I suspect that Jackson expects a colon in the offset, so `+00:00` rather than `+0000`. This is at least what the one-arg `ZonedDateTime.parse()` would expect. As an aside, since your string has an offset in it and no time zone (like `Australia/Sydney`), `OffsetDateTime` would be a more correct class for representing it. – Ole V.V. Dec 01 '19 at 09:05
  • Maybe related: [Convert date into AEST using java](https://stackoverflow.com/questions/48412345/convert-date-into-aest-using-java) – Ole V.V. Dec 01 '19 at 09:08
  • @OleV.V. the time format is correct. it seems that I need to create a Jackson Module for this. – Chathura Wijesinghe Dec 02 '19 at 00:00
  • According to the ISO 8601 standard the colon is optional, but Java only accepts the form with a colon. And Jackson too, it would seem. Sorry. – Ole V.V. Dec 02 '19 at 05:06

0 Answers0