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

ZonedDateTime serialization with @JsonFormat.pattern never uses it while WRITE_DATES_WITH_ZONE_ID enabled #333

Closed
1 task done
verve111 opened this issue Dec 4, 2024 · 9 comments
Milestone

Comments

@verve111
Copy link

verve111 commented Dec 4, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Hi, I'm using JavaTimeModule() in my app with SerializationFeature.WRITE_DATES_WITH_ZONE_ID enabled and there's a strange thing:
When JsonFormat-annotation with pattern is added:

    static class SomeDto {
        @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z")
        private ZonedDateTime time;
    }

Current object is always serialized as an ISO_ZONED_DATE_TIME, e.g. "2024-11-15T18:27:06.921054+01:00[Europe/Germany]", the pattern is not taken into account.
Could you give a hint if this is expected behaviour, thank you!

Version Information

2.18.1

Expected behavior

{"time":"2024-12-02 16:30:00 CET"}

@pjfanning
Copy link
Member

may be related to #330

@JooHyukKim
Copy link
Member

#330 was about JsonFormat.lenient configuration, which we ended up adding more documentation on @jsonformat itself.

Wrt issue here, I think class-level @JsonFormat configuration should override global SerializationFeature.WRITE_DATES_WITH_ZONE_ID. Probably #334 would fix the issue.

@cowtowncoder cowtowncoder changed the title ZonedDateTime serialization with @JsonFormat pattern never uses it while WRITE_DATES_WITH_ZONE_ID enabled ZonedDateTime serialization with @JsonFormat.pattern never uses it while WRITE_DATES_WITH_ZONE_ID enabled Dec 6, 2024
@cowtowncoder cowtowncoder modified the milestones: 2.18.2, 2.18.3 Dec 6, 2024
@JooHyukKim
Copy link
Member

@cowtowncoder Is this closed? 👀

@cowtowncoder
Copy link
Member

@JooHyukKim I did close it, yes. Is there remaining work?

@JooHyukKim
Copy link
Member

Yeah I thought #334 would be related

@cowtowncoder
Copy link
Member

Yes, closed due to #334 fixing this issue. Feel free to re-open issues if they are wrongly closed (with a note).

@JooHyukKim
Copy link
Member

Yeah, was asking because the mentioned PR #334 is still open 👀

@cowtowncoder
Copy link
Member

Whops. So I did not actually yet merge it. My bad, thank you for reminder @JooHyukKim :)

cowtowncoder pushed a commit that referenced this issue Dec 7, 2024
@cowtowncoder
Copy link
Member

Now merged.

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

4 participants