-
-
Notifications
You must be signed in to change notification settings - Fork 1k
#3617 support for target this enum mapping. #3616
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your work on this @Zegveld! I checked it out and played with it a bit, and yes, this solves the problem when an enum is used as a target via The reproducer with an inherit inverse configuration provided by @filiphr is still not solved. So I have created another issue for your fix, which then solves #3437: #3617 I have relinked the PR with the new issue. |
thunderhook
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have enough experience yet and would like @filiphr to take another look at it, I just have a few comments from my side.
| for ( MappingReference targetThis : this.targetThisReferences ) { | ||
| PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) | ||
| .sourceMethod( method ) | ||
| .sourcePropertyName( "test" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have no effect in this case, however this seems fishy - maybe just not set sourcePropertyName at all?
| } | ||
|
|
||
| public boolean shouldDirectlyReturnOnlyMappingResult() { | ||
| return this.returnTypeToConstruct.isEnumType() && this.propertyMappings.size() == 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could come up with more tests. I have no idea what scenarios could be tested, but after checking the coverage report we could provide a test where this.propertyMappings.size() is != 1
Not quite sure though, my coverage report seems to be a bit buggy.
| import org.mapstruct.ap.testutil.ProcessorTest; | ||
| import org.mapstruct.ap.testutil.WithClasses; | ||
|
|
||
| public class Issue2421Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, we would need to change the issue number to 3617 - might aswell add @IssueKey("3617") here.
|
I need to have a better look at this. However, I don't like the fact that this is done using the We currently support string to enum. The solution for this would be to convert the |
You can actually use
It would indeed be better to introduce a |
Indeed, I missed that.
I think that we arleady have an error when using |
| return !method.getOptions().getSubclassMappings().isEmpty() | ||
| && ( method.getOptions().getBeanMapping().getSubclassExhaustiveStrategy().isAbstractReturnTypeAllowed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to know-
( method.getOptions().getBeanMapping().getSubclassExhaustiveStrategy().isAbstractReturnTypeAllowed()
|| isCorrectlySealed()
|| isCorrectlyDefinedTargetThisForEnumTarget() ); ??
fixes #3617