Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in timezone handling for Date created from Joda DateTime between 2.6.2 and 2.6.3 #973

Closed
wilkinsona opened this issue Oct 14, 2015 · 3 comments

Comments

@wilkinsona
Copy link

In 2.6.3, I'm seeing a DateTime that's in UTC move into BST (my timezone) when it's converted into a Date and written as a String. In 2.6.1 and 2.6.2 it stays in UTC. This code reproduces the problem:

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = createObjectMapper();
        DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC);
        System.out.println(objectMapper
                .writeValueAsString(dateTime));
        Date date = dateTime.toDate();
        System.out.println(objectMapper
                .writeValueAsString(date));
    }

    private static ObjectMapper createObjectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(createJodaModule());
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZ"));
        return mapper;
    }

    private static SimpleModule createJodaModule() {
        SimpleModule module = new SimpleModule();
        module.addSerializer(DateTime.class, new DateTimeSerializer(
                new JacksonJodaDateFormat(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss ZZZ")
                        .withZoneUTC())));
            return module;
    }

The output for various versions of Jackson:

2.6.1
"1988-06-25 20:30:00 UTC"
"1988-06-25 20:30:00 +0000"
2.6.2
"1988-06-25 20:30:00 UTC"
"1988-06-25 20:30:00 +0000"
2.6.3
"1988-06-25 20:30:00 UTC"
"1988-06-25 21:30:00 +0100"
@cowtowncoder
Copy link
Member

Could you please re-file this at https://github.com/FasterXML/jackson-datatype-joda/issues as this handling is by Joda? I would transfer it but I don't think github has any easy means to do that.

@philwebb
Copy link

@cowtowncoder Raised here: FasterXML/jackson-datatype-joda#76

GitHub indeed doesn't have a way to transfer issues. When I need to do that I usually edit the original comment, copy the raw markdown then paste it into a new issue.

@cowtowncoder
Copy link
Member

Thanks -- yes, this is unfortunate omission from github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants