@Target(value=TYPE) @Retention(value=CLASS) public @interface MapperConfig
Generally, any settings given via Mapper
take precedence over the settings given via the referenced
MapperConfig
. The lists of referenced mappers given via Mapper.uses()
and
uses()
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 using
InheritConfiguration
or InheritInverseConfiguration
, 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 {
// ...
}
Mapper.config()
Modifier and Type | Optional Element and 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 |
nullValueMappingStrategy
The strategy to be applied when
null is passed as source argument value to mapping methods. |
NullValuePropertyMappingStrategy |
nullValuePropertyMappingStrategy
The strategy to be applied when a source bean property is
null or not present. |
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.
|
public abstract Class<?>[] uses
public abstract Class<?>[] imports
Mapping.expression()
,
Mapping.defaultExpression()
or using
their simple name rather than their fully-qualified name.public abstract ReportingPolicy unmappedSourcePolicy
public abstract ReportingPolicy unmappedTargetPolicy
public abstract ReportingPolicy typeConversionPolicy
public abstract String componentModel
default
: the mapper uses no component model, instances are
typically retrieved via Mappers.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
public abstract String implementationName
<CLASS_NAME>
will be replaced by the
interface/abstract class name.
Defaults to postfixing the name with Impl
: <CLASS_NAME>Impl
implementationPackage()
public abstract String implementationPackage
<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
implementationName()
public abstract CollectionMappingStrategy collectionMappingStrategy
orderDto.addOrderLine()
).public abstract NullValueMappingStrategy nullValueMappingStrategy
null
is passed as source argument value to mapping methods. If no
strategy is configured, NullValueMappingStrategy.RETURN_NULL
will be used by default.null
is passed as source value to mapping methods.public abstract NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy
null
or not present. If no strategy is
configured, NullValuePropertyMappingStrategy.SET_TO_NULL
will be used by default.null
is passed as source property value or the source property
is not present.public abstract MappingInheritanceStrategy mappingInheritanceStrategy
Mapping
,
IterableMapping
, MapMapping
, or BeanMapping
.
If no strategy is configured, MappingInheritanceStrategy.EXPLICIT
will be used as default.
@Mapping
configurations of prototype methods in the interface
annotated with this annotation.public abstract NullValueCheckStrategy nullValueCheckStrategy
Mapper
, BeanMapping
or Mapping
.public abstract InjectionStrategy injectionStrategy
Mapper
.
If no strategy is configured, InjectionStrategy.FIELD
will be used as default.public abstract boolean disableSubMappingMethodsGeneration
true
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.
public abstract Builder builder
Can be overridden by builder()
.
NOTE: In case no builder is defined here, in BeanMapping
or Mapper
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
public abstract Class<? extends Annotation> mappingControl
DeepClone
,
NoComplexMapping
,
MappingControl
public abstract Class<? extends Exception> unexpectedValueMappingException
IllegalArgumentException
will be used by default.
Note:
String
parameter.
Copyright © 2012-2021 MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.