Skip to content

@JsonFormat overriden features don't apply when there are no other options while deserializing ZonedDateTime  #196

@MaciejDobrowolski

Description

@MaciejDobrowolski

After deserializing a following class:

    static class WrapperWithFeatures {
        @JsonFormat(without = JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
        public ZonedDateTime value;

        public WrapperWithFeatures() { }
        public WrapperWithFeatures(ZonedDateTime v) { value = v; }
    }

value field should preserve timezone from the source - but it doesn't. Following test fails:

    @Test
    public void testDeserializationWithZonePreserved() throws Throwable
    {
        WrapperWithFeatures wrapper = JsonMapper.builder()
                .addModule(new JavaTimeModule())
                .build()
                .readerFor(WrapperWithFeatures.class)
                .readValue("{\"value\":\"2000-01-01T12:00+01:00\"}");
        assertEquals("Timezone should be preserved.",
                ZonedDateTime.of(2000, 1, 1, 12, 0, 0 ,0, ZoneOffset.ofHours(1)),
                wrapper.value);
    }

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