Mappers.getMapper(Class clazz) is throwing a ClassNotFoundException when a mapper is defined with a custom implementation name. · Issue #1812 · mapstruct/mapstruct
| Tags | |
|---|---|
| URL | https://github.com/mapstruct/mapstruct/issues/1812 |
Hey guys !
I've discovered what it seems to be an issue with Mappers.getMapper(Class<T> clazz) when a Mapper is defined this way
// Pay attention to the implementationName which has been defined
@Mapper(componentModel = "spring", implementationName = "<CLASS_NAME>V1Impl")
public interface CarMapper {
@Mapping(target = "color", ignore = true)
CarDTO map(Car car);
}
And when we try to retrieve its implementation using Mappers.getMapper(CarMapper.class).
Here is the stacktrace
Caused by: java.lang.ClassNotFoundException: Cannot find implementation for com.example.demo.mappers.v1.CarMapper
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:75)
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:58)
The issue seems to be located here
The code is trying to load a mapper according to the default class implementation name. The one defined by implementationName in annotation @Mapper is not considered here.
I've created a public repo to reproduce this behaviour. see https://github.com/matleclaire/mapstruct-sample-error
I hope it might help.
Mapstruct version : 1.3.0-Final