Package org.mapstruct

Annotation Type Builder


  • @Retention(CLASS)
    @Target({})
    @Experimental
    public @interface Builder
    Configuration of builders, e.g. the name of the final build method.

    Example: Using builder

    
     // Mapper
     @Mapper
     public interface SimpleBuilderMapper {
          @Mapping(target = "name", source = "fullName"),
          @Mapping(target = "job", constant = "programmer"),
          SimpleImmutablePerson toImmutable(SimpleMutablePerson source);
     }
     
    
     // generates
     @Override
     public SimpleImmutablePerson toImmutable(SimpleMutablePerson source) {
          // name method can be changed with parameter buildMethod()
          Builder simpleImmutablePerson = SimpleImmutablePerson.builder();
          simpleImmutablePerson.name( source.getFullName() );
          simpleImmutablePerson.age( source.getAge() );
          simpleImmutablePerson.address( source.getAddress() );
          simpleImmutablePerson.job( "programmer" );
          // ...
     }
     
    Since:
    1.3
    Author:
    Filip Hrisafov
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String buildMethod
      The name of the build method that needs to be invoked on the builder to create the type to be build
      boolean disableBuilder
      Toggling builders on / off.
    • Element Detail

      • buildMethod

        String buildMethod
        The name of the build method that needs to be invoked on the builder to create the type to be build
        Returns:
        the method that needs to tbe invoked on the builder
        Default:
        "build"
      • disableBuilder

        boolean disableBuilder
        Toggling builders on / off. Builders are sometimes used solely for unit testing (fluent testdata) MapStruct will need to use the regular getters /setters in that case.
        Returns:
        when true, no builder patterns will be applied
        Default:
        false