Annotation Type MappingControl


Controls which means of mapping are considered between the source and the target in mappings.

There are several applications of MappingControl conceivable. One application, "deep cloning" is explained below in the example.

Another application is controlling so called "complex mappings", which are not always desirable and sometimes lead to unexpected behaviour and prolonged compilation time.

Example:Cloning of an object

When all methods are allowed, MapStruct would make a shallow copy. It would take the ShelveDTO in the FridgeDTO and directly enter that as target on the target FridgeDTO. By disabling all other kinds of mappings apart from MappingControl.Use.MAPPING_METHOD, see DeepClone MapStruct is forced to generate mapping methods all through the object graph `FridgeDTO` and hence create a deep clone.


 public class FridgeDTO {

     private ShelveDTO shelve;

     public ShelveDTO getShelve() {
         return shelve;
     }

     public void setShelve(ShelveDTO shelve) {
         this.shelve = shelve;
     }
 }
 

 public class ShelveDTO {

     private CoolBeerDTO coolBeer;

     public CoolBeerDTO getCoolBeer() {
         return coolBeer;
     }

     public void setCoolBeer(CoolBeerDTO coolBeer) {
         this.coolBeer = coolBeer;
     }
 }
 

 public class CoolBeerDTO {

     private String beerCount;

     public String getBeerCount() {
         return beerCount;
     }

     public void setBeerCount(String beerCount) {
         this.beerCount = beerCount;
     }
 }
 

 @Mapper(mappingControl = DeepClone.class)
 public interface CloningMapper {

     CloningMapper INSTANCE = Mappers.getMapper( CloningMapper.class );

     FridgeDTO clone(FridgeDTO in);

 }
 
Since:
1.4
Author:
Sjaak Derksen
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Defines the options that can be used for the mapping control.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The type of mapping control that should be used.
  • Element Details

    • value

      The type of mapping control that should be used.
      Returns:
      What should be used for the mapping control