public interface Configuration
Modifier and Type | Interface and Description |
---|---|
static class |
Configuration.AccessLevel
The level at and below which properties can be accessed.
|
Modifier and Type | Method and Description |
---|---|
<T> Configuration |
addValueReader(ValueReader<T> valueReader)
Registers the
valueReader to use when mapping from instances of types T . |
<T> Configuration |
addValueWriter(ValueWriter<T> valueWriter)
Registers the
valueWriter to use when mapping property to instances of types T . |
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, else
null if no condition has been configured. |
Provider<?> |
getProvider()
Returns the Provider used for provisioning destination object instances, else
null 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()
Returns
true if ambiguous properties are ignored or false 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 is
null . |
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 given
accessLevel . |
Configuration |
setFieldMatchingEnabled(boolean enabled)
Sets whether field matching should be enabled.
|
Configuration |
setFullTypeMatchingRequired(boolean required)
Set whether
ConditionalConverter s must define a full 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 given
accessLevel . |
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 the
condition that must apply for a property in order for mapping to take place. |
Configuration |
setProvider(Provider<?> provider)
Sets the
provider to use for providing destination object instances. |
Configuration |
setSkipNullEnabled(boolean enabled)
Sets whether a property should be skipped or not when the property value is
null . |
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
|
<T> Configuration addValueReader(ValueReader<T> valueReader)
valueReader
to use when mapping from instances of types T
.
This method is part of the ModelMapper SPI.
T
- source typevalueReader
- to registerIllegalArgumentException
- if valueReader
is null or if type argument T
is not declared for the valueReader
<T> Configuration addValueWriter(ValueWriter<T> valueWriter)
valueWriter
to use when mapping property to instances of types T
.
This method is part of the ModelMapper SPI.
T
- source typevalueWriter
- to registerIllegalArgumentException
- if valueWriter
is null or if type argument T
is not declared for the valueWriter
Configuration copy()
List<ConditionalConverter<?,?>> getConverters()
This method is part of the ModelMapper SPI.
NameTokenizer getDestinationNameTokenizer()
NameTransformer getDestinationNameTransformer()
NamingConvention getDestinationNamingConvention()
Configuration.AccessLevel getFieldAccessLevel()
setFieldAccessLevel(AccessLevel)
MatchingStrategy getMatchingStrategy()
setMatchingStrategy(MatchingStrategy)
Configuration.AccessLevel getMethodAccessLevel()
setMethodAccessLevel(AccessLevel)
Condition<?,?> getPropertyCondition()
null
if no condition has been configured.setPropertyCondition(Condition)
Provider<?> getProvider()
null
if
no Provider has been configured.setProvider(Provider)
NameTokenizer getSourceNameTokenizer()
setSourceNameTokenizer(NameTokenizer)
NameTransformer getSourceNameTransformer()
NamingConvention getSourceNamingConvention()
List<ValueReader<?>> getValueReaders()
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.
List<ValueWriter<?>> getValueWriters()
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.
boolean isAmbiguityIgnored()
true
if ambiguous properties are ignored or false
if they will result
in an exception.setAmbiguityIgnored(boolean)
boolean isFieldMatchingEnabled()
setFieldMatchingEnabled(boolean)
boolean isFullTypeMatchingRequired()
true
if ConditionalConverter
s must define a full
match in order to be applied. Otherwise conditional converters may also be applied for a
partial
match.
Default is false
.
setFullTypeMatchingRequired(boolean)
boolean isImplicitMappingEnabled()
true
(default), ModelMapper
will implicitly map source to destination properties based on configured conventions. When
false
, only explicit mappings defined in property maps
will be
used.setImplicitMappingEnabled(boolean)
boolean isPreferNestedProperties()
true
(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));
setPreferNestedProperties(boolean)
boolean isSkipNullEnabled()
null
.
When true
, ModelMapper will always not set null
to destination property.setSkipNullEnabled(boolean)
boolean isUseOSGiClassLoaderBridging()
setUseOSGiClassLoaderBridging(boolean)
boolean isDeepCopyEnabled()
setDeepCopyEnabled(boolean)
,
AssignableConverter
boolean isCollectionsMergeEnabled()
true
, mapping a source collection of size m
to a destination collection of size n
with m < n
results
in a collection with the first m
elements mapped from the source and elements from
m+1
to n
being preserved from the destination collection.
When false
the elements of the destination collection are not preserved if they are not present
in the source collection.setCollectionsMergeEnabled(boolean)
,
MergingCollectionConverter
,
NonMergingCollectionConverter
Configuration setAmbiguityIgnored(boolean ignore)
ignore
- whether ambiguity is to be ignoredisAmbiguityIgnored()
Configuration setDestinationNameTokenizer(NameTokenizer nameTokenizer)
IllegalArgumentException
- if nameTokenizer
is nullConfiguration setDestinationNameTransformer(NameTransformer nameTransformer)
IllegalArgumentException
- if nameTransformer
is nullConfiguration setDestinationNamingConvention(NamingConvention namingConvention)
IllegalArgumentException
- if namingConvention
is nullConfiguration setFieldAccessLevel(Configuration.AccessLevel accessLevel)
accessLevel
.
Note: Field access is only used when field
matching
is enabled.
IllegalArgumentException
- if accessLevel
is nullsetFieldMatchingEnabled(boolean)
Configuration setFieldMatchingEnabled(boolean enabled)
false
.enabled
- whether field matching is enabledisFieldMatchingEnabled()
,
setFieldAccessLevel(AccessLevel)
Configuration setFullTypeMatchingRequired(boolean required)
ConditionalConverter
s must define a full
match in
order to be applied. If false
, conditional converters may also be applied for a
partial
match.required
- whether full type matching is required for conditional converters.isFullTypeMatchingRequired()
Configuration setImplicitMappingEnabled(boolean enabled)
true
(default), ModelMapper will
implicitly map source to destination properties based on configured conventions. When
false
, only explicit mappings defined in property maps
will be
used.enabled
- whether implicit matching is enabledisImplicitMappingEnabled()
Configuration setPreferNestedProperties(boolean enabled)
true
(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));
enabled
- whether prefer nested propertiesisPreferNestedProperties()
Configuration setSkipNullEnabled(boolean enabled)
null
.enabled
- whether skip null is enabledisSkipNullEnabled()
Configuration setDeepCopyEnabled(boolean enabled)
false
(default), ModelMapper will
copy the reference to the destination object of a property if they have same type. When true
,
ModelMapper will deep copy the property to destination object.enabled
- enabled whether deep copy is enabledisDeepCopyEnabled()
,
AssignableConverter
Configuration setCollectionsMergeEnabled(boolean enabled)
true
(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.
When false
the destination collection only consists of the elements of the source collection after mapping.enabled
- isCollectionsMergeEnabled()
,
MergingCollectionConverter
,
NonMergingCollectionConverter
Configuration setUseOSGiClassLoaderBridging(boolean useOSGiClassLoaderBridging)
This 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.
useOSGiClassLoaderBridging
- whether to use OSGi Class Loader Bridge. Default is falseisUseOSGiClassLoaderBridging()
Configuration setMatchingStrategy(MatchingStrategy matchingStrategy)
IllegalArgumentException
- if matchingStrategy
is nullConfiguration setMethodAccessLevel(Configuration.AccessLevel accessLevel)
accessLevel
.IllegalArgumentException
- if accessLevel
is nullConfiguration.AccessLevel
Configuration setPropertyCondition(Condition<?,?> condition)
condition
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.IllegalArgumentException
- if condition
is nullConfiguration setProvider(Provider<?> provider)
provider
to use for providing destination object instances.provider
- to registerIllegalArgumentException
- if provider
is nullConfiguration setSourceNameTokenizer(NameTokenizer nameTokenizer)
IllegalArgumentException
- if nameTokenizer
is nullConfiguration setSourceNameTransformer(NameTransformer nameTransformer)
IllegalArgumentException
- if nameTransformer
is nullConfiguration setSourceNamingConvention(NamingConvention namingConvention)
IllegalArgumentException
- if namingConvention
is nullCopyright © 2011–2024. All rights reserved.