Skip to content

fix: Ensure NullValuePropertyMappingStrategy.SET_TO_DEFAULT initializes empty collection/map when target is null #3871

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tangyang9464
Copy link
Contributor

fix: #3865

When both source and target Map/List properties are null and nullValuePropertyMappingStrategy is SET_TO_DEFAULT, the target property should be set to an empty collection instead of remaining null.

This commit adds the necessary else branch to ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl to handle this case correctly.

…es empty collection/map when target is null

Signed-off-by: TangYang <tangyang9464@163.com>
@tangyang9464
Copy link
Contributor Author

@filiphr There was a fixture test about SET_TO_DEFAULT that failed, and I changed the fixture.

I think the bug may be related to this comment,but to be honest, I don’t quite understand what this sentence means.

* <b>Note</b>: some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder
* as target accessor see {@link CollectionMappingStrategy}, MapStruct will always generate a source property
* null check, regardless the value of the {@link NullValuePropertyMappingStrategy} to avoid addition of {@code null}
* to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied.

It's correct for SET_TO_NULL and IGNORE, and the else branch should not be generated. But it doesn't apply to SET_TO_DEFAULT

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.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy