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

Arrays cannot be mapped to collection / iterable using an adder method #3165

Closed
eroznik opened this issue Feb 17, 2023 · 2 comments · Fixed by #3166
Closed

Arrays cannot be mapped to collection / iterable using an adder method #3165

eroznik opened this issue Feb 17, 2023 · 2 comments · Fixed by #3166
Labels
Milestone

Comments

@eroznik
Copy link
Contributor

eroznik commented Feb 17, 2023

Expected behavior

I would expect that given

public class User {
    private String id;
    private String email;
    private Permission[] permissions;
    // more code omitted for brevity
}

I'd be able to get a mapper to map the Java POJO to

message UserDTO {
    string id = 1;
    string email = 2;
    repeated PermissionDTO permissions = 3;
// more code omitted for brevity
}

Which would map the permission array to the proto permissionsList through the adder pattern.

Actual behavior

The auto-code generation fails because the generated code tries to directly add the whole array instead of iterating over it, map each value on its own and add it to the list.

Steps to reproduce the problem

I modified the public Protobuff example so it fails
eroznik/mapstruct-examples@f4c3a4e

The pushed code is using the latest snapshot, mostly because I was using the latest snapshot version while testing it out locally. Keep in mind that the linked commit won't build.

MapStruct Version

All versions that I tested.

@eroznik eroznik added the bug label Feb 17, 2023
@eroznik eroznik changed the title Protobuff list to array mapping fails Array to Protobuff list mapping fails Feb 17, 2023
@filiphr filiphr changed the title Array to Protobuff list mapping fails Array to List mapping with adder fails Apr 15, 2023
@filiphr filiphr added this to the 1.6.0 milestone Apr 15, 2023
@filiphr
Copy link
Member

filiphr commented Apr 15, 2023

Thanks for reporting this @eroznik and thanks for the PR. I've added some comments to the PR (we need some tests before merging it).

I also changed the title, since the problem is not linked to protobuf, but it is generally linked that arrays cannot be mapped to collection / iterable using an adder method.

@eroznik
Copy link
Contributor Author

eroznik commented Apr 15, 2023

Thanks for the review. I'll be adding tests for sure, now that it's confirmed the changes make sense.

eroznik added a commit to eroznik/mapstruct that referenced this issue Apr 15, 2023
eroznik added a commit to eroznik/mapstruct that referenced this issue Apr 15, 2023
eroznik added a commit to eroznik/mapstruct that referenced this issue Apr 23, 2023
@filiphr filiphr changed the title Array to List mapping with adder fails Arrays cannot be mapped to collection / iterable using an adder method Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants