Skip to content

DateTime serialization result is not same as Java 8 ZonedDateTime #92

Open
@chanjarster

Description

@chanjarster

Version: 2.8.8

Below is the test code:

    LocalDateTime localDateTime = new LocalDateTime(2017, 1, 1, 1, 1, 1);

    ZonedDateTime java8ZonedDateTime = ZonedDateTime.ofInstant(localDateTime.toDate().toInstant(), ZoneId.of("Asia/Shanghai"));
    DateTime jodaDateTime = localDateTime.toDateTime(DateTimeZone.forID("Asia/Shanghai"));

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JodaModule());
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    System.out.println(objectMapper.writeValueAsString(java8ZonedDateTime));
    System.out.println(objectMapper.writeValueAsString(jodaDateTime));

ZonedDateTime result is "2017-01-01T01:01:01+08:00"
while DateTime result is "2016-12-31T17:01:01.000Z", which is convert to UTC timezone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pr-welcomeIssue for which progress most likely if someone submits a Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions