Mapping generic type - MapStruct

Viewed 31

I'm trying to make a mapping to a generic type, but I'm having this problem:

error: Can't generate mapping method for a generic type variable source. A map(M baseAccountMongo);

code:

public interface AccountMapper<A extends BaseAccount, M extends BaseAccountMongo> {

    AccountMapper INSTANCE = Mappers.getMapper( AccountMapper.class );

    A map(M baseAccountMongo);
}

do you have any solution for this?

1 Answers

MapStruct is an annotation processor. This means that it generates a mapping during compilation time. Therefore, it doesn't support mapping from generic types, since the types are unknown during compilation time.

e.g. in the provided example MapStruct has no way of knowing which exact type A is and thus cannot create a mapping for it.

Related