Annotation Type MapperConfig
-
@Target(TYPE) @Retention(CLASS) public @interface MapperConfig
Marks a class or interface as configuration source for generated mappers. This allows to share common configurations between several mapper classes.Generally, any settings given via
Mapper
take precedence over the settings given via the referencedMapperConfig
. The lists of referenced mappers given viaMapper.uses()
anduses()
will be merged.Additionally, mapper configuration classes may declare one more prototype mapping methods. These methods are not meant to be invoked themselves (no implementation will generated for mapper config classes), but serve as configuration template for mapping methods declared by actual mapper classes. Depending on the configured
mappingInheritanceStrategy()
, the configuration can be inherited either explicitly usingInheritConfiguration
orInheritInverseConfiguration
, or automatically in case all source and target types are assignable.Example:
// create config @MapperConfig( uses = CustomMapperViaMapperConfig.class, unmappedTargetPolicy = ReportingPolicy.ERROR ) public interface CentralConfig { }
// use config @Mapper(config = CentralConfig.class, uses = { CustomMapperViaMapper.class } ) public interface SourceTargetMapper { // ... }
// result after applying CentralConfig @Mapper( uses = { CustomMapperViaMapper.class, CustomMapperViaMapperConfig.class }, unmappedTargetPolicy = ReportingPolicy.ERROR ) public interface SourceTargetMapper { // ... }
- Author:
- Sjaak Derksen
- See Also:
Mapper.config()
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description Builder
builder
The information that should be used for the builder mappings.CollectionMappingStrategy
collectionMappingStrategy
The strategy to be applied when propagating the value of collection-typed properties.String
componentModel
Specifies the component model to which the generated mapper should adhere.boolean
disableSubMappingMethodsGeneration
If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a sub-mapping method between the two beans.String
implementationName
Specifies the name of the implementation class.String
implementationPackage
Specifies the target package for the generated implementation.Class<?>[]
imports
Additional types for which an import statement is to be added to the generated mapper implementation class.InjectionStrategy
injectionStrategy
Determines whether to use field or constructor injection.Class<? extends Annotation>
mappingControl
Allows detailed control over the mapping process.MappingInheritanceStrategy
mappingInheritanceStrategy
The strategy to use for applying method-level configuration annotations of prototype methods in the interface annotated with this annotation.NullValueCheckStrategy
nullValueCheckStrategy
Determines when to include a null check on the source property value of a bean mapping.NullValueMappingStrategy
nullValueIterableMappingStrategy
The strategy to be applied whennull
is passed as source argument value to anIterableMapping
.NullValueMappingStrategy
nullValueMapMappingStrategy
The strategy to be applied whennull
is passed as source argument value to aMapMapping
.NullValueMappingStrategy
nullValueMappingStrategy
The strategy to be applied whennull
is passed as source argument value to mapping methods.NullValuePropertyMappingStrategy
nullValuePropertyMappingStrategy
The strategy to be applied when a source bean property isnull
or not present.SubclassExhaustiveStrategy
subclassExhaustiveStrategy
Determines how to handle missing implementation for super classes when using theSubclassMapping
.boolean
suppressTimestampInGenerated
Flag indicating whether the addition of a time stamp in the@Generated
annotation should be suppressed.ReportingPolicy
typeConversionPolicy
How lossy (narrowing) conversion, for instance: long to integer should be reported.Class<? extends Exception>
unexpectedValueMappingException
Exception that should be thrown by the generated code if no mapping matches for enums.ReportingPolicy
unmappedSourcePolicy
How unmapped properties of the source type of a mapping should be reported.ReportingPolicy
unmappedTargetPolicy
How unmapped properties of the target type of a mapping should be reported.Class<?>[]
uses
The mapper types used by this mapper.
-
-
-
Element Detail
-
uses
Class<?>[] uses
The mapper types used by this mapper.- Returns:
- The mapper types used by this mapper.
- Default:
- {}
-
-
-
imports
Class<?>[] imports
Additional types for which an import statement is to be added to the generated mapper implementation class. This allows to refer to those types from within mapping expressions given viaMapping.expression()
,Mapping.defaultExpression()
or using their simple name rather than their fully-qualified name.- Returns:
- classes to add in the imports of the generated implementation.
- Since:
- 1.4
- Default:
- {}
-
-
-
unmappedSourcePolicy
ReportingPolicy unmappedSourcePolicy
How unmapped properties of the source type of a mapping should be reported.- Returns:
- The reporting policy for unmapped source properties.
- Since:
- 1.3
- Default:
- org.mapstruct.ReportingPolicy.IGNORE
-
-
-
unmappedTargetPolicy
ReportingPolicy unmappedTargetPolicy
How unmapped properties of the target type of a mapping should be reported.- Returns:
- The reporting policy for unmapped target properties.
- Default:
- org.mapstruct.ReportingPolicy.WARN
-
-
-
typeConversionPolicy
ReportingPolicy typeConversionPolicy
How lossy (narrowing) conversion, for instance: long to integer should be reported.- Returns:
- The reporting policy for type conversion.
- Since:
- 1.3
- Default:
- org.mapstruct.ReportingPolicy.IGNORE
-
-
-
componentModel
String componentModel
Specifies the component model to which the generated mapper should adhere. Supported values are-
default
: the mapper uses no component model, instances are typically retrieved viaMappers.getMapper(Class)
-
cdi
: the generated mapper is an application-scoped CDI bean and can be retrieved via@Inject
-
spring
: the generated mapper is a Spring bean and can be retrieved via@Autowired
-
jsr330
: the generated mapper is annotated with@javax.inject.Named
and@Singleton
, and can be retrieved via@Inject
. The annotations will either be from javax.inject or jakarta.inject, depending on which one is available, with javax.inject having precedence. -
jakarta
: the generated mapper is annotated with@jakarta.inject.Named
and@Singleton
, and can be retrieved via@Inject
.
- Returns:
- The component model for the generated mapper.
- Default:
- "default"
-
-
-
-
implementationName
String implementationName
Specifies the name of the implementation class. The<CLASS_NAME>
will be replaced by the interface/abstract class name.Defaults to postfixing the name with
Impl
:<CLASS_NAME>Impl
- Returns:
- The implementation name.
- See Also:
implementationPackage()
- Default:
- "<CLASS_NAME>Impl"
-
-
-
implementationPackage
String implementationPackage
Specifies the target package for the generated implementation. The<PACKAGE_NAME>
will be replaced by the interface's or abstract class' package.Defaults to using the same package as the mapper interface/abstract class
- Returns:
- the implementation package.
- See Also:
implementationName()
- Default:
- "<PACKAGE_NAME>"
-
-
-
collectionMappingStrategy
CollectionMappingStrategy collectionMappingStrategy
The strategy to be applied when propagating the value of collection-typed properties. By default, only JavaBeans accessor methods (setters or getters) will be used, but it is also possible to invoke a corresponding adder method for each element of the source collection (e.g.orderDto.addOrderLine()
).- Returns:
- The strategy applied when propagating the value of collection-typed properties.
- Default:
- org.mapstruct.CollectionMappingStrategy.ACCESSOR_ONLY
-
-
-
nullValueMappingStrategy
NullValueMappingStrategy nullValueMappingStrategy
The strategy to be applied whennull
is passed as source argument value to mapping methods. If no strategy is configured,NullValueMappingStrategy.RETURN_NULL
will be used by default.- Returns:
- The strategy to be applied when
null
is passed as source value to mapping methods.
- Default:
- org.mapstruct.NullValueMappingStrategy.RETURN_NULL
-
-
-
nullValueIterableMappingStrategy
NullValueMappingStrategy nullValueIterableMappingStrategy
The strategy to be applied whennull
is passed as source argument value to anIterableMapping
. If no strategy is configured, the strategy given vianullValueMappingStrategy()
will be applied, usingNullValueMappingStrategy.RETURN_NULL
by default.- Returns:
- The strategy to be applied when
null
is passed as source value to anIterableMapping
. - Since:
- 1.5
- Default:
- org.mapstruct.NullValueMappingStrategy.RETURN_NULL
-
-
-
nullValueMapMappingStrategy
NullValueMappingStrategy nullValueMapMappingStrategy
The strategy to be applied whennull
is passed as source argument value to aMapMapping
. If no strategy is configured, the strategy given vianullValueMappingStrategy()
will be applied, usingNullValueMappingStrategy.RETURN_NULL
by default.- Returns:
- The strategy to be applied when
null
is passed as source value to aMapMapping
. - Since:
- 1.5
- Default:
- org.mapstruct.NullValueMappingStrategy.RETURN_NULL
-
-
-
nullValuePropertyMappingStrategy
NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy
The strategy to be applied when a source bean property isnull
or not present. If no strategy is configured,NullValuePropertyMappingStrategy.SET_TO_NULL
will be used by default.- Returns:
- The strategy to be applied when
null
is passed as source property value or the source property is not present. - Since:
- 1.3
- Default:
- org.mapstruct.NullValuePropertyMappingStrategy.SET_TO_NULL
-
-
-
mappingInheritanceStrategy
MappingInheritanceStrategy mappingInheritanceStrategy
The strategy to use for applying method-level configuration annotations of prototype methods in the interface annotated with this annotation. Annotations that can be inherited are for exampleMapping
,IterableMapping
,MapMapping
, orBeanMapping
.If no strategy is configured,
MappingInheritanceStrategy.EXPLICIT
will be used as default.- Returns:
- The strategy to use for applying
@Mapping
configurations of prototype methods in the interface annotated with this annotation.
- Default:
- org.mapstruct.MappingInheritanceStrategy.EXPLICIT
-
-
-
nullValueCheckStrategy
NullValueCheckStrategy nullValueCheckStrategy
Determines when to include a null check on the source property value of a bean mapping. Can be overridden by the one onMapper
,BeanMapping
orMapping
.- Returns:
- strategy how to do null checking
- Default:
- org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION
-
-
-
subclassExhaustiveStrategy
SubclassExhaustiveStrategy subclassExhaustiveStrategy
Determines how to handle missing implementation for super classes when using theSubclassMapping
. Can be overridden by the one onBeanMapping
orMapper
.- Returns:
- strategy to handle missing implementation combined with
SubclassMappings
. - Since:
- 1.5
- Default:
- org.mapstruct.SubclassExhaustiveStrategy.COMPILE_ERROR
-
-
-
injectionStrategy
InjectionStrategy injectionStrategy
Determines whether to use field or constructor injection. This is only used on annotated based component models such as CDI, Spring and JSR 330. Can be overridden by the one onMapper
. If no strategy is configured,InjectionStrategy.FIELD
will be used as default.- Returns:
- strategy how to inject
- Default:
- org.mapstruct.InjectionStrategy.FIELD
-
-
-
disableSubMappingMethodsGeneration
boolean disableSubMappingMethodsGeneration
If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a sub-mapping method between the two beans. If this property is set totrue
MapStruct will not try to automatically generate sub-mapping methods.Can be overridden by
Mapper.disableSubMappingMethodsGeneration()
Note: If you need to use
disableSubMappingMethodsGeneration
please contact the MapStruct team at mapstruct.org or github.com/mapstruct/mapstruct to share what problem you are facing with the automatic sub-mapping generation.- Returns:
- whether the automatic generation of sub-mapping methods is disabled
- Since:
- 1.2
- Default:
- false
-
-
-
builder
Builder builder
The information that should be used for the builder mappings. This can be used to define custom build methods for the builder strategy that one uses.Can be overridden by
builder()
.NOTE: In case no builder is defined here, in
BeanMapping
orMapper
and there is a single build method, then that method would be used.If the builder is defined and there is a single method that does not match the name of the build method then a compile error will occur
- Returns:
- the builder information
- Since:
- 1.3
- Default:
- @org.mapstruct.Builder
-
-
-
mappingControl
Class<? extends Annotation> mappingControl
Allows detailed control over the mapping process.- Returns:
- the mapping control
- Since:
- 1.4
- See Also:
DeepClone
,NoComplexMapping
,MappingControl
- Default:
- org.mapstruct.control.MappingControl.class
-
-
-
unexpectedValueMappingException
Class<? extends Exception> unexpectedValueMappingException
Exception that should be thrown by the generated code if no mapping matches for enums. If no exception is configured,IllegalArgumentException
will be used by default.Note:
-
The defined exception should at least have a constructor with a
String
parameter. - If the defined exception is a checked exception then the enum mapping methods should have that exception in the throws clause.
- Returns:
- the exception that should be used in the generated code
- Since:
- 1.4
- Default:
- java.lang.IllegalArgumentException.class
-
The defined exception should at least have a constructor with a
-
-
-
suppressTimestampInGenerated
boolean suppressTimestampInGenerated
Flag indicating whether the addition of a time stamp in the@Generated
annotation should be suppressed. i.e. not be added. The method overrides the flag set through an annotation processor option.- Returns:
- whether the addition of a timestamp should be suppressed
- Since:
- 1.5
- Default:
- false
-
-