Package com.hotels.beans.transformer
Interface Transformer
-
- All Known Implementing Classes:
TransformerImpl
public interface Transformer
Utility methods for populating Mutable, Immutable and Hybrid JavaBeans properties via reflection. The implementations are provided by BeanUtils.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
removeFieldMapping(String destFieldName)
Removes the field mapping for the given field.void
removeFieldTransformer(String destFieldName)
Removes the field transformer for the given field.void
resetFieldsMapping()
Removes all the configured fields mapping.void
resetFieldsTransformer()
Removes all the configured fields transformer.Transformer
setDefaultValueForMissingField(boolean useDefaultValue)
It allows to configure the transformer in order to set a default value in case some field is missing in the source object.<T,K>
Ktransform(T sourceObj, Class<? extends K> targetClass)
Copies all properties from an object to a new one.Transformer
withFieldMapping(FieldMapping... fieldMapping)
Initializes the mapping between fields in the source object and the destination one.Transformer
withFieldTransformer(FieldTransformer... fieldTransformer)
Initializes the field transformer functions.
-
-
-
Method Detail
-
transform
<T,K> K transform(T sourceObj, Class<? extends K> targetClass)
Copies all properties from an object to a new one.- Type Parameters:
T
- the Source object typeK
- the target object type- Parameters:
sourceObj
- the source objecttargetClass
- the destination object class- Returns:
- a copy of the source object into the destination object
- Throws:
IllegalArgumentException
- if any parameter is invalid
-
withFieldMapping
Transformer withFieldMapping(FieldMapping... fieldMapping)
Initializes the mapping between fields in the source object and the destination one.- Parameters:
fieldMapping
- the field mapping- Returns:
- the
Transformer
instance
-
removeFieldMapping
void removeFieldMapping(String destFieldName)
Removes the field mapping for the given field.- Parameters:
destFieldName
- the field name in the destination object
-
resetFieldsMapping
void resetFieldsMapping()
Removes all the configured fields mapping.
-
withFieldTransformer
Transformer withFieldTransformer(FieldTransformer... fieldTransformer)
Initializes the field transformer functions. The transformer function returns directly the field value.- Parameters:
fieldTransformer
- the fields transformer function- Returns:
- the
Transformer
instance
-
removeFieldTransformer
void removeFieldTransformer(String destFieldName)
Removes the field transformer for the given field.- Parameters:
destFieldName
- the field name in the destination object
-
resetFieldsTransformer
void resetFieldsTransformer()
Removes all the configured fields transformer.
-
setDefaultValueForMissingField
Transformer setDefaultValueForMissingField(boolean useDefaultValue)
It allows to configure the transformer in order to set a default value in case some field is missing in the source object. If set to true the default value is set, if false if it raises a:MissingFieldException
in case of missing fields.- Parameters:
useDefaultValue
- true in case the default value should be set, false if it should raise a:MissingFieldException
in case of missing field.- Returns:
- the
Transformer
instance
-
-