Skip to content

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

@eroznik

Description

@eroznik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions