Package org.mapstruct

Annotation Type MappingTarget


@Target(PARAMETER) @Retention(CLASS) public @interface MappingTarget
Declares a parameter of a mapping method to be the target of the mapping.

Not more than one parameter can be declared as MappingTarget.

NOTE: The parameter passed as a mapping target must not be null.

Example 1: Update exist bean without return value


 @Mapper
 public interface HumanMapper {
     void updateHuman(HumanDto humanDto, @MappingTarget Human human);
 }
 

 // generates
 @Override
 public void updateHuman(HumanDto humanDto, Human human) {
     human.setName( humanDto.getName() );
     // ...
 }
 

Example 2: Update exist bean and return it


 @Mapper
 public interface HumanMapper {
     Human updateHuman(HumanDto humanDto, @MappingTarget Human human);
 }
 
// generates:

 @Override
 public Human updateHuman(HumanDto humanDto, Human human) {
     // ...
     human.setName( humanDto.getName() );
     return human;
 }
Author:
Andreas Gudian