joschi/jackson-datatype-threetenbp

Deserialization does not honor @JsonFormat

carragom opened this issue · 2 comments

When deserializing a string like 2015-10-18T06:00:00.000Z to a LocalDateTime using @JsonFormat(pattern = "yyyy[-]MM[-]dd'T'HH[:]mm[:]ss.SX") the process fails with a root exception like this:

Caused by: org.threeten.bp.format.DateTimeParseException: Text '2015-10-18T06:00:00.000Z' could not be parsed, unparsed text found at index 23
    at org.threeten.bp.format.DateTimeFormatter.parseToBuilder(DateTimeFormatter.java:1590) ~[threetenbp-1.3.1.jar:1.3.1]
    at org.threeten.bp.format.DateTimeFormatter.parse(DateTimeFormatter.java:1491) ~[threetenbp-1.3.1.jar:1.3.1]
    at org.threeten.bp.LocalDateTime.parse(LocalDateTime.java:444) ~[threetenbp-1.3.1.jar:1.3.1]
    at org.threeten.bp.LocalDateTime.parse(LocalDateTime.java:429) ~[threetenbp-1.3.1.jar:1.3.1]
    at com.fasterxml.jackson.datatype.threetenbp.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:103) ~[jackson-datatype-threetenbp-2.5.0.jar:2.5.0]
    at com.fasterxml.jackson.datatype.threetenbp.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:35) ~[jackson-datatype-threetenbp-2.5.0.jar:2.5.0]
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520) ~[jackson-databind-2.6.3.jar:2.6.3]
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95) ~[jackson-databind-2.6.3.jar:2.6.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:222) ~[jackson-databind-2.6.3.jar:2.6.3]
    ... 100 common frames omitted

It looks like the Deserializer does not honor the pattern in @JsonFormat.

The pattern used in my previous post is incorrect and the actual cause of the exception. The correct pattern should be yyyy[-]MM[-]dd'T'HH[:]mm[:]ss.SSSX. But the problem still applies, the deserializers do not seem to honor the pattern while the serializers do.