GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Mapping `ZonedDateTime` or `OffsetDateTime` to `LocalDateTime` · Issue #4027 · mapstruct/mapstruct

Mapping ZonedDateTime or OffsetDateTime to LocalDateTime #4027

New issue
Copy link
New issue
Copy link
Closed
#4047
Closed
Mapping ZonedDateTime or OffsetDateTime to LocalDateTime#4027
#4047
Copy link
Labels
bug
Milestone
1.7.x

Description

@JanecekPetr
JanecekPetr
opened on Mar 31, 2026
Issue body actions

Expected behavior

This is very similar to:

  • Mapping LocalDate to LocalDateTime and reverse #3304
  • Support for implicit conversion between java.time.LocalDate and java.time.LocalDateTime #3199
    ...which was implemented in 1.6, so I expected all time-related conversions to behave the same.

However, given:

record Zoned(ZonedDateTime zonedDateTime) {}
record Local(LocalDateTime localDateTime) {}

@Mapper
interface ZonedToLocalMapper {
    @Mapping(target = "localDateTime", source = "zonedDateTime")
    Local toLocal(Zoned zoned);
}

I'd expect the mapper to just do

localDateTime = zonedDateTime.toLocalDateTime();

The reverse fails nicely, that's correct as converting LocalDateTime to ZonedDateTime requires a Zone.

Actual behavior

however, we see this monstrosity

localDateTime = xmlGregorianCalendarToLocalDateTime( zonedDateTimeToXmlGregorianCalendar( zonedDateTime ) );

with a lot of javax.xml.datatype classes. Those should be unnecessary.

Steps to reproduce the problem

record Zoned(ZonedDateTime zonedDateTime) {}
record Local(LocalDateTime localDateTime) {}

@Mapper
interface ZonedToLocalMapper {
    @Mapping(target = "localDateTime", source = "zonedDateTime")
    Local toLocal(Zoned zoned);
}

and the sane for OffsetDateTime on the left side and likely Instant and LocalTime and LocalDate on the right side etc.

MapStruct Version

1.6.3

Reacted by Bernhard

Activity

  1. JanecekPetr
    added
    bug
    on Mar 31, 2026
  2. JanecekPetr commented on Mar 31, 2026

    @JanecekPetr
    JanecekPetr
    on Mar 31, 2026
    Author
    More actions

    Similarly, I now see that neither ZonedDateTime nor OffsetDateTime cannot be converted to Instant at all, even though zonedDateTime.toInstant() exists.

  3. JanecekPetr
    changed the title [-]Mapping `ZonedDateTime` to `LocalDateTime`[/-] [+]Mapping `ZonedDateTime` or `OffsetDateTime` to `LocalDateTime`[/+] on Mar 31, 2026
  4. Takch02 commented on Apr 5, 2026

    @Takch02
    Takch02
    on Apr 5, 2026
    Contributor
    More actions

    @JanecekPetr hi, Can I work on?

  5. filiphr commented on May 1, 2026

    @filiphr
    filiphr
    on May 1, 2026
    Member
    More actions

    @Takch02 you are more than welcome to contribute this.

    @JanecekPetr thanks for raising this. This is a valid bug

  6. filiphr
    added this to the 1.7.x milestone on May 1, 2026
  7. Takch02 commented on May 1, 2026

    @Takch02
    Takch02
    on May 1, 2026
    Contributor
    More actions

    @filiphr Thank you, I try it!

  8. Takch02
    added a commit that references this issue on May 3, 2026

    mapstruct#4027 Add license Header

    f0279a9
  9. Takch02
    added 3 commits that reference this issue on May 23, 2026

    mapstruct#4027 Add support for implicit conversion between ZonedDateT…

    7fe6088

    mapstruct#4027 Add support for conversion Instant/LocalDateTime, Inst…

    5fda707

    mapstruct#4027 Add documentation

    db58594
  10. hduelme
    added a commit that references this issue on May 24, 2026

    #4027 Fix mapping ZonedDateTime or OffsetDateTime to LocalDateTime or…

    428fd27
  11. hduelme
    closed this as completedin #4047on May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      • 1.7.xNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.