#3617 support for target this enum mapping.#3616
#3617 support for target this enum mapping.#3616Zegveld wants to merge 1 commit intomapstruct:mainfrom
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.
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.
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.
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.
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.
just to know-
( method.getOptions().getBeanMapping().getSubclassExhaustiveStrategy().isAbstractReturnTypeAllowed()
|| isCorrectlySealed()
|| isCorrectlyDefinedTargetThisForEnumTarget() ); ??
fixes #3617