Interface Configuration


public interface Configuration
Configures conventions used during the matching process.
  • Method Details

    • addValueReader

      <T> Configuration addValueReader(ValueReader<T> valueReader)
      Registers the valueReader to use when mapping from instances of types T.

      This method is part of the ModelMapper SPI.

      Type Parameters:
      T - source type
      Parameters:
      valueReader - to register
      Throws:
      IllegalArgumentException - if valueReader is null or if type argument T is not declared for the valueReader
    • addValueWriter

      <T> Configuration addValueWriter(ValueWriter<T> valueWriter)
      Registers the valueWriter to use when mapping property to instances of types T.

      This method is part of the ModelMapper SPI.

      Type Parameters:
      T - source type
      Parameters:
      valueWriter - to register
      Throws:
      IllegalArgumentException - if valueWriter is null or if type argument T is not declared for the valueWriter
    • 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.
      See Also:
    • getDestinationNameTransformer

      NameTransformer getDestinationNameTransformer()
      Returns the destination name transformer.
      See Also:
    • getDestinationNamingConvention

      NamingConvention getDestinationNamingConvention()
      Returns the destination naming convention.
      See Also:
    • 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, else null if no condition has been configured.
      See Also:
    • getProvider

      Provider<?> getProvider()
      Returns the Provider used for provisioning destination object instances, else null 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.
      See Also:
    • getSourceNamingConvention

      NamingConvention getSourceNamingConvention()
      Gets the source naming convention.
      See Also:
    • 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()
      Returns true if ambiguous properties are ignored or false if they will result in an exception.
      See Also:
    • isFieldMatchingEnabled

      boolean isFieldMatchingEnabled()
      Returns whether field matching is enabled.
      See Also:
    • isFullTypeMatchingRequired

      boolean isFullTypeMatchingRequired()
      Returns true if ConditionalConverters must define a full match in order to be applied. Otherwise conditional converters may also be applied for a partial match.

      Default is false.

      See Also:
    • isImplicitMappingEnabled

      boolean isImplicitMappingEnabled()
      Returns whether implicit mapping should be enabled. When 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.
      See Also:
    • isPreferNestedProperties

      boolean isPreferNestedProperties()
      Returns whether nested properties were preferred when ModelMapper were building the type map with implicit mapping. When 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));
       
      See Also:
    • isSkipNullEnabled

      boolean isSkipNullEnabled()
      Returns whether a property mapping will be skipped if the property value is null. When true, ModelMapper will always not set null 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:
    • isCollectionsMergeEnabled

      boolean isCollectionsMergeEnabled()
      Returns whether collections should be 'merged' when mapped. When 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.
      See Also:
    • 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:
    • setDestinationNameTokenizer

      Configuration setDestinationNameTokenizer(NameTokenizer nameTokenizer)
      Sets the tokenizer to be applied to destination property and class names during the matching process.
      Throws:
      IllegalArgumentException - if nameTokenizer 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 - if nameTransformer is null
    • setDestinationNamingConvention

      Configuration setDestinationNamingConvention(NamingConvention namingConvention)
      Sets the convention used to identify destination property names during the matching process.
      Throws:
      IllegalArgumentException - if namingConvention is null
    • setFieldAccessLevel

      Configuration setFieldAccessLevel(Configuration.AccessLevel accessLevel)
      Indicates that fields should be eligible for matching at the given accessLevel.

      Note: Field access is only used when field matching is enabled.

      Throws:
      IllegalArgumentException - if accessLevel is null
      See Also:
    • setFieldMatchingEnabled

      Configuration setFieldMatchingEnabled(boolean enabled)
      Sets whether field matching should be enabled. When true, mapping may take place between accessible fields. Default is false.
      Parameters:
      enabled - whether field matching is enabled
      See Also:
    • setFullTypeMatchingRequired

      Configuration setFullTypeMatchingRequired(boolean required)
      Set whether ConditionalConverters must define a full match in order to be applied. If false, conditional converters may also be applied for a partial match.
      Parameters:
      required - whether full type matching is required for conditional converters.
      See Also:
    • setImplicitMappingEnabled

      Configuration setImplicitMappingEnabled(boolean enabled)
      Sets whether implicit mapping should be enabled. When 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.
      Parameters:
      enabled - whether implicit matching is enabled
      See Also:
    • setPreferNestedProperties

      Configuration setPreferNestedProperties(boolean enabled)
      Sets whether nested properties were preferred when ModelMapper were building the type map with implicit mapping. When 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));
       
      Parameters:
      enabled - whether prefer nested properties
      See Also:
    • setSkipNullEnabled

      Configuration setSkipNullEnabled(boolean enabled)
      Sets whether a property should be skipped or not when the property value is null.
      Parameters:
      enabled - whether skip null is enabled
      See Also:
    • setDeepCopyEnabled

      Configuration setDeepCopyEnabled(boolean enabled)
      Sets whether deep copy should be enabled. When 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.
      Parameters:
      enabled - enabled whether deep copy is enabled
      See Also:
    • setCollectionsMergeEnabled

      Configuration setCollectionsMergeEnabled(boolean enabled)
      Sets whether the 'merging' of collections should be enabled. When 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.
      Parameters:
      enabled -
      See Also:
    • 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-osgi

      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.

      Parameters:
      useOSGiClassLoaderBridging - whether to use OSGi Class Loader Bridge. Default is false
      See Also:
    • setMatchingStrategy

      Configuration setMatchingStrategy(MatchingStrategy matchingStrategy)
      Sets the strategy used to match source properties to destination properties.
      Throws:
      IllegalArgumentException - if matchingStrategy is null
    • setMethodAccessLevel

      Configuration setMethodAccessLevel(Configuration.AccessLevel accessLevel)
      Indicates that methods should be eligible for matching at the given accessLevel.
      Throws:
      IllegalArgumentException - if accessLevel is null
      See Also:
    • setPropertyCondition

      Configuration setPropertyCondition(Condition<?,?> condition)
      Sets the 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.
      Throws:
      IllegalArgumentException - if condition is null
    • setProvider

      Configuration setProvider(Provider<?> provider)
      Sets the provider to use for providing destination object instances.
      Parameters:
      provider - to register
      Throws:
      IllegalArgumentException - if provider 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 - if nameTokenizer 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 - if nameTransformer is null
    • setSourceNamingConvention

      Configuration setSourceNamingConvention(NamingConvention namingConvention)
      Sets the convention used to identify source property names during the matching process.
      Throws:
      IllegalArgumentException - if namingConvention is null