@Experimental @Target(value=METHOD) @Retention(value=CLASS) public @interface BeforeMapping
Mapper.uses()
in order to
be used in a mapping method.
Only methods with return type void
may be annotated with this annotation.
If the method has parameters, the method invocation is only generated if all parameters can be assigned by the source or target parameters of the mapping method:
@
MappingTarget
is populated with the target instance of the mapping.
@
TargetType
is populated with the target type of the mapping.@
MappingTarget
parameter, it is invoked
directly at the beginning of the applicable mapping method. If it contains a @
MappingTarget
parameter, the method is invoked after the target parameter has been initialized in the mapping method.
All before-mapping methods that can be applied to a mapping method will be used. Their order is determined by their location of definition:
Mapper.uses()
.
Mapper.uses()
are searched for after-mapping methods in the order specified
in the annotation.Example:
@BeforeMapping
public void calledWithoutArgs() {
// ...
}
@BeforeMapping
public void calledWithSourceAndTargetType(SourceEntity anySource, @TargetType Class<?> targetType) {
// ...
}
@BeforeMapping
public void calledWithSourceAndTarget(Object anySource, @MappingTarget TargetDto target) {
// ...
}
public abstract TargetDto toTargetDto(SourceEntity source);
// generates:
public TargetDto toTargetDto(SourceEntity source) {
calledWithoutArgs();
calledWithSourceAndTargetType( source, TargetDto.class );
if ( source == null ) {
return null;
}
TargetDto targetDto = new TargetDto();
calledWithSourceAndTarget( source, targetDto );
// actual mapping code
return targetDto;
}
AfterMapping
Copyright © 2012-2015 Gunnar Morling; All rights reserved. Released under the Apache Software License 2.0.