org.mapstruct.Builder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapstruct Show documentation
Show all versions of mapstruct Show documentation
An annotation processor for generating type-safe bean mappers
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.mapstruct.util.Experimental;
/**
* 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 {@link #buildMethod()}
* Builder simpleImmutablePerson = SimpleImmutablePerson.builder();
* simpleImmutablePerson.name( source.getFullName() );
* simpleImmutablePerson.age( source.getAge() );
* simpleImmutablePerson.address( source.getAddress() );
* simpleImmutablePerson.job( "programmer" );
* // ...
* }
*
*
* @author Filip Hrisafov
*
* @since 1.3
*/
@Retention(RetentionPolicy.CLASS)
@Target({})
@Experimental
public @interface Builder {
/**
* The name of the build method that needs to be invoked on the builder to create the type to be build
*
* @return the method that needs to tbe invoked on the builder
*/
String buildMethod() default "build";
/**
* 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.
*
* @return when true, no builder patterns will be applied
*/
boolean disableBuilder() default false;
}