@Target(value=PARAMETER) @Retention(value=CLASS) public @interface TargetType
Not more than one parameter can be declared as TargetType
and that parameter needs to be of type
Class
(may be parameterized), or a super-type of it.
Example:
public class EntityFactory {
public <T extends BaseEntity> T createEntity(@TargetType Class<T> entityClass) {
return // ... custom factory logic
}
}
@Mapper(uses = EntityFactory.class)
public interface CarMapper {
CarEntity carDtoToCar(CarDto dto);
}
// generates
public class CarMapperImpl implements CarMapper {
private final EntityFactory entityFactory = new EntityFactory();
@Override
public CarEntity carDtoToCar(CarDto dto) {
if ( dto == null ) {
return null;
}
CarEntity carEntity = entityFactory.createEntity( CarEntity.class );
return carEntity;
}
}
Copyright © 2012-2021 MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.