Skip to content

#1997 Use builders to construct empty objects in update wrapper#2733

Merged
filiphr merged 1 commit intomapstruct:masterfrom
filiphr:1997-update-empty-object-construction
Jan 30, 2022
Merged

#1997 Use builders to construct empty objects in update wrapper#2733
filiphr merged 1 commit intomapstruct:masterfrom
filiphr:1997-update-empty-object-construction

Conversation

@filiphr
Copy link
Member

@filiphr filiphr commented Jan 23, 2022

Fixes #1997

Copy link
Contributor

@sjaakd sjaakd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factory methods accept source parameters (I believe). However, I don't think we use them in property mappings, right? (Only for constructing a return type). The case that you test is creating a default empty object with a builder.

Would it be interesting to se what happens if we do accept a source parameter (for the non default case)? I guess that would be a different PR, right? The use case would be an extension of this one though. Jus as using object factories for property mappings.

@filiphr
Copy link
Member Author

filiphr commented Jan 30, 2022

Factory methods accept source parameters (I believe). However, I don't think we use them in property mappings, right? (Only for constructing a return type). The case that you test is creating a default empty object with a builder.

Yes they do access source parameters and they still do. This is done in line 420 in PropertyMapping. However, if there is no factory method to construct an object then we do something similar like we do in the BeanMappingMethod.

The change that this PRs is doing is to use the builder if there is one for constructing the target object for update mappings.

@filiphr filiphr merged commit aed3ff5 into mapstruct:master Jan 30, 2022
@filiphr filiphr deleted the 1997-update-empty-object-construction branch January 30, 2022 11:38
chenzijia12300 added a commit to chenzijia12300/mapstruct that referenced this pull request Aug 20, 2022
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.

MapStruct does not always use builders in target-object

2 participants