Class AbstractMapStrategy
- All Implemented Interfaces:
MapStrategy
- Direct Known Subclasses:
MapCollectionStrategy
,MapToDynamicClassStrategy
,MapToInstanceStrategy
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractMapStrategy
(BeanMapper beanMapper, Configuration configuration) -
Method Summary
Modifier and TypeMethodDescriptionconvert
(Object value, Class<?> targetClass, BeanPropertyMatch beanPropertyMatch) Converts a value into the target class.<T,
S> BeanMatch getBeanMatch
(Class<S> sourceClazz, Class<T> targetClazz) getConstructorArguments
(S source, BeanMatch beanMatch) Composes theConstructorArguments
-object for the given source andBeanMatch
-object.getConverterOptional
(Class<?> sourceClass, Class<?> targetClass) boolean
isMappable
(String packageName) Verifies whether the package is part of the beans which may be mapped by the bean mapper.boolean
isMappableClass
(Class<?> clazz) Verifies whether the class is part of the beans which may be mapped by the BeanMapper.<S,
T> T processProperties
(S source, T target, BeanMatch beanMatch) Try to match the source fields on the target fields from the given classes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.beanmapper.strategy.MapStrategy
map
-
Field Details
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Details
-
AbstractMapStrategy
-
-
Method Details
-
getConfiguration
-
getBeanMapper
-
getConstructorArguments
Composes theConstructorArguments
-object for the given source andBeanMatch
-object.This method is used specifically by the
MapToClassStrategy
and theMapToRecordStrategy
.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
-
convert
Converts a value into the target class.- Parameters:
value
- the value to converttargetClass
- the target classbeanPropertyMatch
- contains the fields belonging to the source/target field match- Returns:
- the converted value
-
processProperties
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 typeT
- 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
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
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
-