Skip to content

#4141 Use a presence check for Optional nested sources in update mappings - #4142

Open
jasper-vandemalle wants to merge 1 commit into
mapstruct:mainfrom
jasper-vandemalle:4141-optional-nested-update
Open

jasper-vandemalle wants to merge 1 commit into
mapstruct:mainfrom
jasper-vandemalle:4141-optional-nested-update

Conversation

@jasper-vandemalle

Copy link
Copy Markdown
Contributor

Fixes #4141

In an update mapping, an Optional nested source is guarded with != null before the forged update method is called. An Optional source is normally not null, so Optional.empty() never reaches the SET_TO_NULL / SET_TO_DEFAULT branch: the existing target is kept, and a null nested target gets an empty new instance. The guard in UpdateWrapper now also checks isPresent() for Optional sources.

A null Optional reference behaves as before, since that likely depends on the outcome of #4123 and #4128.

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

Successfully merging this pull request may close these issues.

Empty Optional nested source in an update mapping does not clear the target and creates an empty nested target

1 participant