Skip to content
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

Support for using current element index as source value when mapping collections #3566

Open
crizzis opened this issue Mar 27, 2024 · 0 comments

Comments

@crizzis
Copy link

crizzis commented Mar 27, 2024

Use case

It would be nice to be able to map the index of the current element in the source list to a property in the target collection. I imagine sth like @Mapping(source = "#currentIndex" target = "recordIndexField")

(bonus points, I suppose, for being able to reference it in other contexts as well, e.g. expression = "java(someCustomMethod(#currentIndex))")

Generated Code

No response

Possible workarounds

The only workaround I could think of was to iterate over the collection programmatically, which meant it was also clearer to use a per-element mapper, instead of a collection mapper

MapStruct Version

No response

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

No branches or pull requests

1 participant