Interface Configuration
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
The level at and below which properties can be accessed. -
Method Summary
Modifier and TypeMethodDescription<T> Configuration
addValueReader
(ValueReader<T> valueReader) Registers thevalueReader
to use when mapping from instances of typesT
.<T> Configuration
addValueWriter
(ValueWriter<T> valueWriter) Registers thevalueWriter
to use when mapping property to instances of typesT
.copy()
Returns a copy of the Configuration.List<ConditionalConverter<?,
?>> Gets the ordered list of internal conditional converters that are used to perform type conversion.Returns the destination name tokenizer.Returns the destination name transformer.Returns the destination naming convention.Returns the field access level.Gets the matching strategy.Returns the method access level.Condition<?,
?> Returns the Condition that must apply for a property in order for mapping to take place, elsenull
if no condition has been configured.Provider<?>
Returns the Provider used for provisioning destination object instances, elsenull
if no Provider has been configured.Returns the source name tokenizer.Returns the source name transformer.Gets the source naming convention.List<ValueReader<?>>
Gets a thread-safe, mutable, ordered list of internal and user-defined ValueReaders that are used to read source object values during mapping.List<ValueWriter<?>>
Gets a thread-safe, mutable, ordered list of internal and user-defined ValueWriters that are used to write destination object values during mapping.boolean
Returnstrue
if ambiguous properties are ignored orfalse
if they will result in an exception.boolean
Returns whether collections should be 'merged' when mapped.boolean
Returns whether the deep copy feature is enabled.boolean
Returns whether field matching is enabled.boolean
boolean
Returns whether implicit mapping should be enabled.boolean
Returns whether nested properties were preferred when ModelMapper were building the type map with implicit mapping.boolean
Returns whether a property mapping will be skipped if the property value isnull
.boolean
Returns whether OSGi Class Loader Bridging is required.setAmbiguityIgnored
(boolean ignore) Sets whether destination properties that match more than one source property should be ignored.setCollectionsMergeEnabled
(boolean enabled) Sets whether the 'merging' of collections should be enabled.setDeepCopyEnabled
(boolean enabled) Sets whether deep copy should be enabled.setDestinationNameTokenizer
(NameTokenizer nameTokenizer) Sets the tokenizer to be applied to destination property and class names during the matching process.setDestinationNameTransformer
(NameTransformer nameTransformer) Sets the name transformer used to transform destination property and class names during the matching process.setDestinationNamingConvention
(NamingConvention namingConvention) Sets the convention used to identify destination property names during the matching process.setFieldAccessLevel
(Configuration.AccessLevel accessLevel) Indicates that fields should be eligible for matching at the givenaccessLevel
.setFieldMatchingEnabled
(boolean enabled) Sets whether field matching should be enabled.setFullTypeMatchingRequired
(boolean required) Set whetherConditionalConverter
s must define afull
match in order to be applied.setImplicitMappingEnabled
(boolean enabled) Sets whether implicit mapping should be enabled.setMatchingStrategy
(MatchingStrategy matchingStrategy) Sets the strategy used to match source properties to destination properties.setMethodAccessLevel
(Configuration.AccessLevel accessLevel) Indicates that methods should be eligible for matching at the givenaccessLevel
.setPreferNestedProperties
(boolean enabled) Sets whether nested properties were preferred when ModelMapper were building the type map with implicit mapping.setPropertyCondition
(Condition<?, ?> condition) Sets thecondition
that must apply for a property in order for mapping to take place.setProvider
(Provider<?> provider) Sets theprovider
to use for providing destination object instances.setSkipNullEnabled
(boolean enabled) Sets whether a property should be skipped or not when the property value isnull
.setSourceNameTokenizer
(NameTokenizer nameTokenizer) Sets the tokenizer to be applied to source property and class names during the matching process.setSourceNameTransformer
(NameTransformer nameTransformer) Sets the name transformer used to transform source property and class names during the matching process.setSourceNamingConvention
(NamingConvention namingConvention) Sets the convention used to identify source property names during the matching process.setUseOSGiClassLoaderBridging
(boolean useOSGiClassLoaderBridging) Sets whether to use an OSGi Class Loader Bridge as described in the following article: https://www.infoq.com/articles/code-generation-with-osgi
-
Method Details
-
addValueReader
Registers thevalueReader
to use when mapping from instances of typesT
.This method is part of the ModelMapper SPI.
- Type Parameters:
T
- source type- Parameters:
valueReader
- to register- Throws:
IllegalArgumentException
- ifvalueReader
is null or if type argumentT
is not declared for thevalueReader
-
addValueWriter
Registers thevalueWriter
to use when mapping property to instances of typesT
.This method is part of the ModelMapper SPI.
- Type Parameters:
T
- source type- Parameters:
valueWriter
- to register- Throws:
IllegalArgumentException
- ifvalueWriter
is null or if type argumentT
is not declared for thevalueWriter
-
copy
Configuration copy()Returns a copy of the Configuration. -
getConverters
List<ConditionalConverter<?,?>> getConverters()Gets the ordered list of internal conditional converters that are used to perform type conversion. This list is mutable and may be modified to control which converters are used to perform type conversion along with the order in which converters are selected.This method is part of the ModelMapper SPI.
-
getDestinationNameTokenizer
NameTokenizer getDestinationNameTokenizer()Returns the destination name tokenizer. -
getDestinationNameTransformer
NameTransformer getDestinationNameTransformer()Returns the destination name transformer. -
getDestinationNamingConvention
NamingConvention getDestinationNamingConvention()Returns the destination naming convention. -
getFieldAccessLevel
Configuration.AccessLevel getFieldAccessLevel()Returns the field access level.- See Also:
-
getMatchingStrategy
MatchingStrategy getMatchingStrategy()Gets the matching strategy.- See Also:
-
getMethodAccessLevel
Configuration.AccessLevel getMethodAccessLevel()Returns the method access level.- See Also:
-
getPropertyCondition
Condition<?,?> getPropertyCondition()Returns the Condition that must apply for a property in order for mapping to take place, elsenull
if no condition has been configured.- See Also:
-
getProvider
Provider<?> getProvider()Returns the Provider used for provisioning destination object instances, elsenull
if no Provider has been configured.- See Also:
-
getSourceNameTokenizer
NameTokenizer getSourceNameTokenizer()Returns the source name tokenizer.- See Also:
-
getSourceNameTransformer
NameTransformer getSourceNameTransformer()Returns the source name transformer. -
getSourceNamingConvention
NamingConvention getSourceNamingConvention()Gets the source naming convention. -
getValueReaders
List<ValueReader<?>> getValueReaders()Gets a thread-safe, mutable, ordered list of internal and user-defined ValueReaders that are used to read source object values during mapping. This list is may be modified to control which ValueReaders are used to along with the order in which ValueReaders are selected for a source type.The returned List throws an IllegalArgumentException when attempting to add or set a ValueReader for which the type argument
T
has not been defined.This method is part of the ModelMapper SPI.
-
getValueWriters
List<ValueWriter<?>> getValueWriters()Gets a thread-safe, mutable, ordered list of internal and user-defined ValueWriters that are used to write destination object values during mapping. This list is may be modified to control which ValueWriters are used to along with the order in which ValueWriters are selected for a destination type.The returned List throws an IllegalArgumentException when attempting to add or set a ValueWriter for which the type argument
T
has not been defined.This method is part of the ModelMapper SPI.
-
isAmbiguityIgnored
boolean isAmbiguityIgnored()Returnstrue
if ambiguous properties are ignored orfalse
if they will result in an exception.- See Also:
-
isFieldMatchingEnabled
boolean isFieldMatchingEnabled()Returns whether field matching is enabled.- See Also:
-
isFullTypeMatchingRequired
boolean isFullTypeMatchingRequired()Returnstrue
ifConditionalConverter
s must define afull
match in order to be applied. Otherwise conditional converters may also be applied for apartial
match.Default is
false
.- See Also:
-
isImplicitMappingEnabled
boolean isImplicitMappingEnabled()Returns whether implicit mapping should be enabled. Whentrue
(default), ModelMapper will implicitly map source to destination properties based on configured conventions. Whenfalse
, only explicit mappings defined inproperty maps
will be used.- See Also:
-
isPreferNestedProperties
boolean isPreferNestedProperties()Returns whether nested properties were preferred when ModelMapper were building the type map with implicit mapping. Whentrue
(default), ModelMapper will prefer looking for nested properties for a mapping definition. This option should be disabled when you are trying to map a model contains circular reference.modelMapper.createTypeMap(SourceTree.class, DestinationTree.class, modelMapper.getConfiguration().copy().setPreferNestedProperties(false));
- See Also:
-
isSkipNullEnabled
boolean isSkipNullEnabled()Returns whether a property mapping will be skipped if the property value isnull
. Whentrue
, ModelMapper will always not setnull
to destination property.- See Also:
-
isUseOSGiClassLoaderBridging
boolean isUseOSGiClassLoaderBridging()Returns whether OSGi Class Loader Bridging is required.- See Also:
-
isDeepCopyEnabled
boolean isDeepCopyEnabled()Returns whether the deep copy feature is enabled.- See Also:
-
setDeepCopyEnabled(boolean)
AssignableConverter
-
isCollectionsMergeEnabled
boolean isCollectionsMergeEnabled()Returns whether collections should be 'merged' when mapped. Whentrue
, mapping a source collection of sizem
to a destination collection of sizen
withm < n
results in a collection with the firstm
elements mapped from the source and elements fromm+1
ton
being preserved from the destination collection. Whenfalse
the elements of the destination collection are not preserved if they are not present in the source collection.- See Also:
-
setCollectionsMergeEnabled(boolean)
MergingCollectionConverter
NonMergingCollectionConverter
-
setAmbiguityIgnored
Sets whether destination properties that match more than one source property should be ignored. When true, ambiguous destination properties are skipped during the matching process. When false, a ConfigurationException is thrown when ambiguous properties are encountered.- Parameters:
ignore
- whether ambiguity is to be ignored- See Also:
-
setDestinationNameTokenizer
Sets the tokenizer to be applied to destination property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTokenizer
is null
-
setDestinationNameTransformer
Sets the name transformer used to transform destination property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTransformer
is null
-
setDestinationNamingConvention
Sets the convention used to identify destination property names during the matching process.- Throws:
IllegalArgumentException
- ifnamingConvention
is null
-
setFieldAccessLevel
Indicates that fields should be eligible for matching at the givenaccessLevel
.Note: Field access is only used when
field matching
is enabled.- Throws:
IllegalArgumentException
- ifaccessLevel
is null- See Also:
-
setFieldMatchingEnabled
Sets whether field matching should be enabled. When true, mapping may take place between accessible fields. Default isfalse
.- Parameters:
enabled
- whether field matching is enabled- See Also:
-
setFullTypeMatchingRequired
Set whetherConditionalConverter
s must define afull
match in order to be applied. Iffalse
, conditional converters may also be applied for apartial
match.- Parameters:
required
- whether full type matching is required for conditional converters.- See Also:
-
setImplicitMappingEnabled
Sets whether implicit mapping should be enabled. Whentrue
(default), ModelMapper will implicitly map source to destination properties based on configured conventions. Whenfalse
, only explicit mappings defined inproperty maps
will be used.- Parameters:
enabled
- whether implicit matching is enabled- See Also:
-
setPreferNestedProperties
Sets whether nested properties were preferred when ModelMapper were building the type map with implicit mapping. Whentrue
(default), ModelMapper will prefer looking for nested properties for a mapping definition. This option should be disabled when you are trying to map a model contains circular reference.modelMapper.createTypeMap(SourceTree.class, DestinationTree.class, modelMapper.getConfiguration().copy().setPreferNestedProperties(false));
- Parameters:
enabled
- whether prefer nested properties- See Also:
-
setSkipNullEnabled
Sets whether a property should be skipped or not when the property value isnull
.- Parameters:
enabled
- whether skip null is enabled- See Also:
-
setDeepCopyEnabled
Sets whether deep copy should be enabled. Whenfalse
(default), ModelMapper will copy the reference to the destination object of a property if they have same type. Whentrue
, ModelMapper will deep copy the property to destination object.- Parameters:
enabled
- enabled whether deep copy is enabled- See Also:
-
isDeepCopyEnabled()
AssignableConverter
-
setCollectionsMergeEnabled
Sets whether the 'merging' of collections should be enabled. Whentrue
(default), ModelMapper will map the elements of the source collection to the destination collection and keep any elements of the destination collection when the source collection is smaller than the destination collection. Whenfalse
the destination collection only consists of the elements of the source collection after mapping.- Parameters:
enabled
-- See Also:
-
isCollectionsMergeEnabled()
MergingCollectionConverter
NonMergingCollectionConverter
-
setUseOSGiClassLoaderBridging
Sets whether to use an OSGi Class Loader Bridge as described in the following article: https://www.infoq.com/articles/code-generation-with-osgiThis eliminates the need for forcing ModelMapper users to add custom OSGi imports to cglib's internals.
In addition to that, the Class Loader Bridge will attempt to solve the issue described in the following StackOverflow topic: https://stackoverflow.com/questions/47854086/cglib-creating-class-proxy-in-osgi-results-in-noclassdeffounderror
Ideally, this is expected to eliminate class loading issues in OSGi environments that were caused by missing custom imports.
Note: If Class Loader Bridging is selected, then the source and destination class types must not be package-private. That is because in Java, two classes are only consider equal to the JRE if they were loaded with the same class loader even if they otherwise represent an identical class. The same is true for Java packages. If a class is loaded with a different class loader, it cannot get private-package access to any classes (or class members) that belong to another class loader.
- Parameters:
useOSGiClassLoaderBridging
- whether to use OSGi Class Loader Bridge. Default is false- See Also:
-
setMatchingStrategy
Sets the strategy used to match source properties to destination properties.- Throws:
IllegalArgumentException
- ifmatchingStrategy
is null
-
setMethodAccessLevel
Indicates that methods should be eligible for matching at the givenaccessLevel
.- Throws:
IllegalArgumentException
- ifaccessLevel
is null- See Also:
-
setPropertyCondition
Sets thecondition
that must apply for a property in order for mapping to take place. This is overridden by any property conditions defined in a TypeMap or PropertyMap.- Throws:
IllegalArgumentException
- ifcondition
is null
-
setProvider
Sets theprovider
to use for providing destination object instances.- Parameters:
provider
- to register- Throws:
IllegalArgumentException
- ifprovider
is null
-
setSourceNameTokenizer
Sets the tokenizer to be applied to source property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTokenizer
is null
-
setSourceNameTransformer
Sets the name transformer used to transform source property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTransformer
is null
-
setSourceNamingConvention
Sets the convention used to identify source property names during the matching process.- Throws:
IllegalArgumentException
- ifnamingConvention
is null
-