Package org.mapstruct

Annotation Type InheritConfiguration


@Target(METHOD) @Retention(CLASS) public @interface InheritConfiguration
Advises the code generator to apply the configuration (as given via Mapping, IterableMapping etc.) from another mapping method (declared on the same mapper type) or prototype method (declared on a mapper config class referenced via Mapper.config()) to the annotated method as well.

If no method can be identified unambiguously as configuration source (i.e. several candidate methods with matching source and target type exist), the name of the method to inherit from must be specified via name().

Mapping.expression(), Mapping.constant(), Mapping.defaultExpression() and Mapping.defaultValue() are not inverse inherited

A typical use case is annotating an update method so it inherits all mappings from a corresponding "standard" mapping method:

 
 @Mappings({
     @Mapping(target="make", source="brand"),
     @Mapping(target="seatCount", source="numberOfSeats")
 })
 CarDto carToCarDto(Car car);

 @InheritConfiguration
 void updateCarDto(Car car, @MappingTarget CarDto carDto);
 
 
Author:
Sjaak Derksen
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The name of the mapping method to inherit the mappings from.
  • Element Details

    • name

      String name
      The name of the mapping method to inherit the mappings from. Needs only to be specified in case more than one method with matching source and target type exists.
      Returns:
      The name of the mapping method to inherit the mappings from.
      Default:
      ""