Skip to content

Builder not Invoked for Generic Classes #2932

Description

@91wzhang

MapStruct version: 1.5.2.Final
Lombok version: 1.18.20

Hi team/community,
I am new to MapStruct. I have been trying to get it working with our existing code where Lombok @value @builder patterns are used.
I have got the mapper working pretty quickly thanks to the documentation and examples. However I failed to get it working with a generic class.

@Builder
public class Record<T> {
    // ...
}

public class ARecordDto {
    // ...
}

@Mapper
public interface ARecordMapper {

    Record<A> toRecord(ARecordDto source);
    // ...
}

Pretty standard but the generated code is trying to invoke the all args constructor which is private. This behavior is different from other non generic classes I have tried (where the builder is correctly used).

I used Lombok to generate the builder. But I have also tried the delomboked version.

The reason is seemingly because when it tries to find the build method from the builder class, it checks the return type of the builder matches the type element. In generic builder's case the buildMethod.getReturnType() returns a ClassReader instance which fails the JavacTypes subType check against the Type instance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions