Class AbstractMapStrategy

java.lang.Object
io.beanmapper.strategy.AbstractMapStrategy
All Implemented Interfaces:
MapStrategy
Direct Known Subclasses:
MapCollectionStrategy, MapToDynamicClassStrategy, MapToInstanceStrategy

public abstract class AbstractMapStrategy extends Object implements MapStrategy
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
  • Constructor Details

  • Method Details

    • getConfiguration

      public Configuration getConfiguration()
    • getBeanMapper

      public BeanMapper getBeanMapper()
    • getConstructorArguments

      public <S> ConstructorArguments getConstructorArguments(S source, BeanMatch beanMatch)
      Composes the ConstructorArguments-object for the given source and BeanMatch-object.

      This method is used specifically by the MapToClassStrategy and the MapToRecordStrategy.

      The source-class is checked for the presence of the BeanConstruct-annotation. If the annotation is present, the names of the fields described by the annotation will be stored in the values-array of the method.

      If no BeanConstruct-annotation is present, a check will be performed to see if the target-class is a record. If so, the values-array will be set to the result of the Records.getRecordFieldNames(Class)-method, which essentially loops through all the RecordComponent-objects associated with the target-class, and returns an array of their names.

      Lastly, if the values-array is null, null will be returned. Otherwise, a new ConstructorArguments-object will be returned, using the source-object, the BeanMatch, and the values-array.

      Type Parameters:
      S - The type of the source-object.
      Parameters:
      source - The source-object that will be mapped to the target.
      beanMatch - The BeanMatch that will be used to map the source to the target.
      Returns:
      ConstructorArguments-object constructed from the source, beanMatch and values taken from either the BeanConstruct-annotation, or RecordComponents.
    • getBeanMatch

      public <T, S> BeanMatch getBeanMatch(Class<S> sourceClazz, Class<T> targetClazz)
    • convert

      public Object convert(Object value, Class<?> targetClass, BeanPropertyMatch beanPropertyMatch)
      Converts a value into the target class.
      Parameters:
      value - the value to convert
      targetClass - the target class
      beanPropertyMatch - contains the fields belonging to the source/target field match
      Returns:
      the converted value
    • processProperties

      public <S, T> T processProperties(S source, T target, BeanMatch beanMatch)
      Try to match the source fields on the target fields from the given classes. First get all fields on the right level with method getAllFields. Second match the fields and handle encapsulated classes. Finally copy the data from the source to the target.
      Type Parameters:
      S - The source type
      T - The target type
      Parameters:
      source - The source from which the values get copied.
      target - The target to which the values get copied.
      beanMatch - the matchup of source and target
      Returns:
      A filled target object.
    • isMappableClass

      public boolean isMappableClass(Class<?> clazz)
      Verifies whether the class is part of the beans which may be mapped by the BeanMapper. This logic is used when nested classes are encountered which need to be treated in a similar way as the main source/ target classes.
      Parameters:
      clazz - the class to be verified against the allowed packages
      Returns:
      true if the class may be mapped, false if it may not
    • isMappable

      public boolean isMappable(String packageName)
      Verifies whether the package is part of the beans which may be mapped by the bean mapper. This logic is used when nested classes are encountered which need to be treated in a similar way as the main source/ target classes.
      Parameters:
      packageName - the package
      Returns:
      true if the class may be mapped, false if it may not
    • getConverterOptional

      public BeanConverter getConverterOptional(Class<?> sourceClass, Class<?> targetClass)