Package org.mapstruct

Annotation Type InheritInverseConfiguration

  • @Target(METHOD)
    public @interface InheritInverseConfiguration
    Advises the code generator to apply all the Mappings from an inverse mapping method to the annotated method as well. An inverse mapping method is a method which has the annotated method's source type as target type (return type or indicated through a parameter annotated with MappingTarget) and the annotated method's target type as source type.

    Any mappings given on the annotated method itself are added to those mappings inherited from the inverse method. In case of a conflict local mappings take precedence over inherited mappings.

    If more than one matching inverse method exists, the name of the method to inherit the configuration from must be specified via name()

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


     public interface HumanMapper {
          Human toHuman(HumanDto humanDto);
          HumanDto toHumanDto(Human human);
     // generates
     public class HumanMapperImpl implements HumanMapper {
          public Human toHuman(HumanDto humanDto) {
              if ( humanDto == null ) {
                  return null;
              Human human = new Human();
              human.setName( humanDto.getName() );
              return human;
          public HumanDto toHumanDto(Human human) {
              if ( human == null ) {
                  return null;
              HumanDto humanDto = new HumanDto();
              humanDto.setName( human.getName() );
              return humanDto;
     public interface CarMapper {
     @Mapping( target = "seatCount", source = "numberOfSeats")
     @Mapping( target = "enginePower", source = "engineClass", ignore=true) // NOTE: source specified as well
     CarDto carToDto(Car car);
     @Mapping(target = "numberOfSeats", ignore = true)
     // no need to specify a mapping with ignore for "engineClass": specifying source above will assume
     Car carDtoToCar(CarDto carDto);
    Sjaak Derksen
    • Optional Element Summary

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

      • name

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