Interface Configuration
-
public interface Configuration
Configures conventions used during the matching process.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Configuration.AccessLevel
The level at and below which properties can be accessed.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <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
.Configuration
copy()
Returns a copy of the Configuration.List<ConditionalConverter<?,?>>
getConverters()
Gets the ordered list of internal conditional converters that are used to perform type conversion.NameTokenizer
getDestinationNameTokenizer()
Returns the destination name tokenizer.NameTransformer
getDestinationNameTransformer()
Returns the destination name transformer.NamingConvention
getDestinationNamingConvention()
Returns the destination naming convention.Configuration.AccessLevel
getFieldAccessLevel()
Returns the field access level.MatchingStrategy
getMatchingStrategy()
Gets the matching strategy.Configuration.AccessLevel
getMethodAccessLevel()
Returns the method access level.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.Provider<?>
getProvider()
Returns the Provider used for provisioning destination object instances, elsenull
if no Provider has been configured.NameTokenizer
getSourceNameTokenizer()
Returns the source name tokenizer.NameTransformer
getSourceNameTransformer()
Returns the source name transformer.NamingConvention
getSourceNamingConvention()
Gets the source naming convention.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.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.boolean
isAmbiguityIgnored()
Returnstrue
if ambiguous properties are ignored orfalse
if they will result in an exception.boolean
isCollectionsMergeEnabled()
Returns whether collections should be 'merged' when mapped.boolean
isDeepCopyEnabled()
Returns whether the deep copy feature is enabled.boolean
isFieldMatchingEnabled()
Returns whether field matching is enabled.boolean
isFullTypeMatchingRequired()
boolean
isImplicitMappingEnabled()
Returns whether implicit mapping should be enabled.boolean
isPreferNestedProperties()
Returns whether nested properties were preferred when ModelMapper were building the type map with implicit mapping.boolean
isSkipNullEnabled()
Returns whether a property mapping will be skipped if the property value isnull
.boolean
isUseOSGiClassLoaderBridging()
Returns whether OSGi Class Loader Bridging is required.Configuration
setAmbiguityIgnored(boolean ignore)
Sets whether destination properties that match more than one source property should be ignored.Configuration
setCollectionsMergeEnabled(boolean enabled)
Sets whether the 'merging' of collections should be enabled.Configuration
setDeepCopyEnabled(boolean enabled)
Sets whether deep copy should be enabled.Configuration
setDestinationNameTokenizer(NameTokenizer nameTokenizer)
Sets the tokenizer to be applied to destination property and class names during the matching process.Configuration
setDestinationNameTransformer(NameTransformer nameTransformer)
Sets the name transformer used to transform destination property and class names during the matching process.Configuration
setDestinationNamingConvention(NamingConvention namingConvention)
Sets the convention used to identify destination property names during the matching process.Configuration
setFieldAccessLevel(Configuration.AccessLevel accessLevel)
Indicates that fields should be eligible for matching at the givenaccessLevel
.Configuration
setFieldMatchingEnabled(boolean enabled)
Sets whether field matching should be enabled.Configuration
setFullTypeMatchingRequired(boolean required)
Set whetherConditionalConverter
s must define afull
match in order to be applied.Configuration
setImplicitMappingEnabled(boolean enabled)
Sets whether implicit mapping should be enabled.Configuration
setMatchingStrategy(MatchingStrategy matchingStrategy)
Sets the strategy used to match source properties to destination properties.Configuration
setMethodAccessLevel(Configuration.AccessLevel accessLevel)
Indicates that methods should be eligible for matching at the givenaccessLevel
.Configuration
setPreferNestedProperties(boolean enabled)
Sets whether nested properties were preferred when ModelMapper were building the type map with implicit mapping.Configuration
setPropertyCondition(Condition<?,?> condition)
Sets thecondition
that must apply for a property in order for mapping to take place.Configuration
setProvider(Provider<?> provider)
Sets theprovider
to use for providing destination object instances.Configuration
setSkipNullEnabled(boolean enabled)
Sets whether a property should be skipped or not when the property value isnull
.Configuration
setSourceNameTokenizer(NameTokenizer nameTokenizer)
Sets the tokenizer to be applied to source property and class names during the matching process.Configuration
setSourceNameTransformer(NameTransformer nameTransformer)
Sets the name transformer used to transform source property and class names during the matching process.Configuration
setSourceNamingConvention(NamingConvention namingConvention)
Sets the convention used to identify source property names during the matching process.Configuration
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 Detail
-
addValueReader
<T> Configuration addValueReader(ValueReader<T> valueReader)
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
<T> Configuration addValueWriter(ValueWriter<T> valueWriter)
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:
setFieldAccessLevel(AccessLevel)
-
getMatchingStrategy
MatchingStrategy getMatchingStrategy()
Gets the matching strategy.- See Also:
setMatchingStrategy(MatchingStrategy)
-
getMethodAccessLevel
Configuration.AccessLevel getMethodAccessLevel()
Returns the method access level.- See Also:
setMethodAccessLevel(AccessLevel)
-
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:
setPropertyCondition(Condition)
-
getProvider
Provider<?> getProvider()
Returns the Provider used for provisioning destination object instances, elsenull
if no Provider has been configured.- See Also:
setProvider(Provider)
-
getSourceNameTokenizer
NameTokenizer getSourceNameTokenizer()
Returns the source name tokenizer.- See Also:
setSourceNameTokenizer(NameTokenizer)
-
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:
setAmbiguityIgnored(boolean)
-
isFieldMatchingEnabled
boolean isFieldMatchingEnabled()
Returns whether field matching is enabled.- See Also:
setFieldMatchingEnabled(boolean)
-
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:
setFullTypeMatchingRequired(boolean)
-
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:
setImplicitMappingEnabled(boolean)
-
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:
setPreferNestedProperties(boolean)
-
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:
setSkipNullEnabled(boolean)
-
isUseOSGiClassLoaderBridging
boolean isUseOSGiClassLoaderBridging()
Returns whether OSGi Class Loader Bridging is required.- See Also:
setUseOSGiClassLoaderBridging(boolean)
-
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
Configuration setAmbiguityIgnored(boolean ignore)
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:
isAmbiguityIgnored()
-
setDestinationNameTokenizer
Configuration setDestinationNameTokenizer(NameTokenizer nameTokenizer)
Sets the tokenizer to be applied to destination property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTokenizer
is null
-
setDestinationNameTransformer
Configuration setDestinationNameTransformer(NameTransformer nameTransformer)
Sets the name transformer used to transform destination property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTransformer
is null
-
setDestinationNamingConvention
Configuration setDestinationNamingConvention(NamingConvention namingConvention)
Sets the convention used to identify destination property names during the matching process.- Throws:
IllegalArgumentException
- ifnamingConvention
is null
-
setFieldAccessLevel
Configuration setFieldAccessLevel(Configuration.AccessLevel accessLevel)
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(boolean)
-
setFieldMatchingEnabled
Configuration setFieldMatchingEnabled(boolean enabled)
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:
isFieldMatchingEnabled()
,setFieldAccessLevel(AccessLevel)
-
setFullTypeMatchingRequired
Configuration setFullTypeMatchingRequired(boolean required)
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:
isFullTypeMatchingRequired()
-
setImplicitMappingEnabled
Configuration setImplicitMappingEnabled(boolean enabled)
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:
isImplicitMappingEnabled()
-
setPreferNestedProperties
Configuration setPreferNestedProperties(boolean enabled)
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:
isPreferNestedProperties()
-
setSkipNullEnabled
Configuration setSkipNullEnabled(boolean enabled)
Sets whether a property should be skipped or not when the property value isnull
.- Parameters:
enabled
- whether skip null is enabled- See Also:
isSkipNullEnabled()
-
setDeepCopyEnabled
Configuration setDeepCopyEnabled(boolean enabled)
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
Configuration setCollectionsMergeEnabled(boolean enabled)
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
Configuration 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-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:
isUseOSGiClassLoaderBridging()
-
setMatchingStrategy
Configuration setMatchingStrategy(MatchingStrategy matchingStrategy)
Sets the strategy used to match source properties to destination properties.- Throws:
IllegalArgumentException
- ifmatchingStrategy
is null
-
setMethodAccessLevel
Configuration setMethodAccessLevel(Configuration.AccessLevel accessLevel)
Indicates that methods should be eligible for matching at the givenaccessLevel
.- Throws:
IllegalArgumentException
- ifaccessLevel
is null- See Also:
Configuration.AccessLevel
-
setPropertyCondition
Configuration setPropertyCondition(Condition<?,?> condition)
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
Configuration setProvider(Provider<?> provider)
Sets theprovider
to use for providing destination object instances.- Parameters:
provider
- to register- Throws:
IllegalArgumentException
- ifprovider
is null
-
setSourceNameTokenizer
Configuration setSourceNameTokenizer(NameTokenizer nameTokenizer)
Sets the tokenizer to be applied to source property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTokenizer
is null
-
setSourceNameTransformer
Configuration setSourceNameTransformer(NameTransformer nameTransformer)
Sets the name transformer used to transform source property and class names during the matching process.- Throws:
IllegalArgumentException
- ifnameTransformer
is null
-
setSourceNamingConvention
Configuration setSourceNamingConvention(NamingConvention namingConvention)
Sets the convention used to identify source property names during the matching process.- Throws:
IllegalArgumentException
- ifnamingConvention
is null
-
-