-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
Add option to map Collections to Immutable Lists #3334
Comments
Thanks for the detailed request @holistic-developer. We'll have this into consideration. Currently, we are focused on the 1.6 release, so we can start looking into this maybe after that. If someone is interested in contributing this, feel free to let us know |
I got bored on a rainy Sunday afternoon, so I gave it a go. See #3356. I tried to be as little invasive as possible. My draft introduces a new annotation, public interface SomeMapper {
Target map(Source source);
@Unmodifiable List<Target> map(List<Source> sources);
} Let me know what you think 😄 |
Sorry for spamming, but are there any news about this? |
Sorry @j-be, we've been busy with other things. I'll try to carve out some time to review this. I am not sure if going with a new annotation for this is the right approach, I would prefer something via |
@filiphr I've rewritten it to take the parameter via |
Thanks @j-be. I've put this on 1.6.0.Beta2 and will try to review it soon. |
Use case
By default, when generating a mapping method using an interface, the following would lead to generated code returning an ArrayList.
generates:
(convertToAbc is also defined in the same interface)
There could be an option in the @mapping annotation to control whether or not an immutable collection is returned from the mapping function.
Generated Code
List.copyOf(list)
wraps the existing collection into an unmodifiable version.Alternatively the following would also be possible:
Possible workarounds
My current workaround is to override these mapping functions by providing a default implementation that does the mapping using a stream and the toList collector.
MapStruct Version
1.5.5.Final
The text was updated successfully, but these errors were encountered: