@Experimental @Target(value=METHOD) @Retention(value=CLASS) public @interface AfterMapping
return
statement
of the mapping method. The method can be implemented in an abstract mapper class or be declared in a type (class or
interface) referenced in 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.All after-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:
@AfterMapping
public void calledWithoutArgs() {
// ...
}
@AfterMapping
public void calledWithSourceAndTargetType(SourceEntity anySource, @TargetType Class<?> targetType) {
// ...
}
@AfterMapping
public void calledWithSourceAndTarget(Object anySource, @MappingTarget TargetDto target) {
// ...
}
public abstract TargetDto toTargetDto(SourceEntity source);
// generates:
public TargetDto toTargetDto(SourceEntity source) {
if ( source == null ) {
return null;
}
TargetDto targetDto = new TargetDto();
// actual mapping code
calledWithoutArgs();
calledWithSourceAndTargetType( source, TargetDto.class );
calledWithSourceAndTarget( source, targetDto );
return targetDto;
}
BeforeMapping
Copyright © 2012-2016 Gunnar Morling; All rights reserved. Released under the Apache Software License 2.0.