Package org.mapstruct.control
Annotation Type MappingControl
-
@Retention(CLASS) @Repeatable(MappingControls.class) @Target(ANNOTATION_TYPE) public @interface 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 theFridgeDTO
and directly enter that as target on the targetFridgeDTO
. By disabling all other kinds of mappings apart fromMappingControl.Use.MAPPING_METHOD
, seeDeepClone
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
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description MappingControl.Use
value
-
-
-
Element Detail
-
value
MappingControl.Use value
-
-