Package org.mapstruct
Annotation Type SourceParameterCondition
-
@Target(METHOD) @Retention(CLASS) public @interface SourceParameterCondition
This annotation marks a method as a check method to check if a source parameter needs to be mapped.By default, source parameters are checked against
null
, unless they are primitives.Check methods have to return
boolean
. The following parameters are accepted for the presence check methods:- The mapping source parameter
@
Context
parameter
The following implementation ofpublic class PresenceCheckUtils { @SourceParameterCondition public static boolean isDefined(Car car) { return car != null && car.getId() != null; } } @Mapper(uses = PresenceCheckUtils.class) public interface CarMapper { CarDto map(Car car); }
CarMapper
will be generated:public class CarMapperImpl implements CarMapper { @Override public CarDto map(Car car) { if ( !PresenceCheckUtils.isDefined( car ) ) { return null; } CarDto carDto = new CarDto(); carDto.setId( car.getId() ); // ... return carDto; } }
- Since:
- 1.6
- Author:
- Filip Hrisafov
- See Also:
@Condition