Skip to content

Adjust LocalDate / LocalDateTime deserializer to support DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE #71

@nezda

Description

@nezda

When deserializing from a long, UTC should be specified to be in keeping with

http://wiki.fasterxml.com/JacksonFAQDateHandling

  • Jackson defaults to GMT/UTC ("How come this time is off by 9 hours?")

To be even more flexible, the DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE feature I wasn't aware of could be mapped from and utilized here too.

Looks like similar approach to #29 would work https://github.com/FasterXML/jackson-datatype-joda/blob/master/src/main/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateDeserializer.java#L40

I'm currently "working around" this with DateTimeZone.setDefault(DateTimeZone.UTC); but this is problematic.

Test case: timestamp 1238544000000L in my timezone is 3/31/2009 but 4/1/2009 in UTC

@Test
  public void aprilFools() {
    final long aprilFools = 1238544000000L;
    System.err.println("date "+new LocalDate(aprilFools));
    System.err.println("UTC date "+new LocalDate(aprilFools, DateTimeZone.UTC));
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions