#1321 Support index for list properties #3813
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Although this is not planned for 1.7.0 I had a look at it.
Some notes about the PR:
Using a
List<...>
directly as parameter is not possible. It shows:"Can't generate mapping method from iterable type from java stdlib to non-iterable type."
which I think is okay, because this doesn't work in other scenarios yet.Currently there are two compile errors when you try to use an index on a type that is not a List:
"Can't access element with index because "drivers" is not of type List."
"No property named "drivers[0].name" exists in source parameter(s). Did you mean "drivers"?
See org.mapstruct.ap.test.collection.index.ListIndexMappingTest.errorWhenSourceIsStringInsteadOfList
I tried to remove the second one, but after thinking about it, it does not harm to also provide the alternatives with "Did you mean ...". WDYT?
When currently using the index for target properties the following error is raised:
"Unknown property "%s" in type %s for target name "%s". Did you mean "%s"?"
I think this is okay, but we can of course implement a dedicated error message that indexes are not allowed for targets.
About
@InheritInverseConfiguration
I have a test for this, using
@InheritInverseConfiguration
. Properties reversed like this just get ignored. I'm not sure if there should be some kind of warning. Or at least a message that is printed in verbose mode.Anywas, it seems that
org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java:668
is the only code that needs to exclude it to be ignored using@InheritInverseConfiguration
. Maybe there are some other test cases I missed.When the PR looks good, there is still some documentation to be done: