Content-Length: 256536 | pFad | http://github.com/mapstruct/mapstruct/pull/3813

29 #1321 Support index for list properties by thunderhook · Pull Request #3813 · mapstruct/mapstruct · GitHub
Skip to content

#1321 Support index for list properties #3813

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

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
1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/mapstruct/mapstruct/pull/3813

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy