Skip to content

Conversation

@thunderhook
Copy link
Contributor

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.

@Mapping(target = ".", source = "source[0]")
PersonDto mapPerson(List<Person> source);

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:

  • add feature in reference docs
  • look for passages in javadoc where this should be noted.

@thunderhook thunderhook linked an issue Feb 9, 2025 that may be closed by this pull request
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.

Allow indexing for object list

2 participants