Package org.mapstruct
Annotation Type 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 ElementsModifier and TypeOptional ElementDescriptionThe name of the build method that needs to be invoked on the builder to create the type to be buildbooleanToggling builders on / off.
-
Element Details
-
buildMethod
String buildMethodThe 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 disableBuilderToggling 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
-