Class TransformerImpl

    • Constructor Detail

      • TransformerImpl

        public TransformerImpl()
    • Method Detail

      • transform

        protected final <T,​K> K transform​(T sourceObj,
                                                java.lang.Class<? extends K> targetClass,
                                                java.lang.String breadcrumb)
        Copies all properties from an object to a new one.
        Type Parameters:
        T - the Source object type
        K - the target object type
        Parameters:
        sourceObj - the source object
        targetClass - the destination object class
        breadcrumb - the full path of the current field starting from his ancestor
        Returns:
        a copy of the source object into the destination object
      • transform

        protected final <T,​K> void transform​(T sourceObj,
                                                   K targetObject,
                                                   java.lang.String breadcrumb)
        Copies all properties from an object to a new one.
        Type Parameters:
        T - the Source object type
        K - the target object type
        Parameters:
        sourceObj - the source object
        targetObject - the destination object
        breadcrumb - the full path of the current field starting from his ancestor
      • handleInjectionException

        protected <T,​K> K handleInjectionException​(T sourceObj,
                                                         java.lang.Class<K> targetClass,
                                                         java.lang.reflect.Constructor constructor,
                                                         java.lang.String breadcrumb,
                                                         java.lang.Object[] constructorArgs,
                                                         boolean forceConstructorInjection,
                                                         java.lang.Exception e)
        Handles the exception thrown by method: injectValues. In case an exception is raised due to missing parameter names it tries to inject through the constructor anyway.
        Type Parameters:
        T - the sourceObj object type
        K - the target object type
        Parameters:
        sourceObj - sourceObj the source object
        targetClass - the destination object class
        constructor - the all args constructor
        breadcrumb - the full path of the current field starting from his ancestor
        constructorArgs - the constructor arguments
        forceConstructorInjection - if true it forces the injection trough constructor
        e - the raised exception
        Returns:
        a copy of the source object into the destination object
        Throws:
        InvalidBeanException - InvalidBeanException if the target object is not compliant with the requirements
      • canBeInjectedByConstructorParams

        protected boolean canBeInjectedByConstructorParams​(java.lang.reflect.Constructor constructor)
        Checks if the source class field names can be retrieved from the constructor parameters.
        Parameters:
        constructor - the all args constructor
        Returns:
        true if the parameter names are defined or the parameters are annotated with: ConstructorArg
      • getConstructorArgsValues

        protected <T,​K> java.lang.Object[] getConstructorArgsValues​(T sourceObj,
                                                                          java.lang.Class<K> targetClass,
                                                                          java.lang.reflect.Constructor constructor,
                                                                          java.lang.String breadcrumb)
        Retrieves all the constructor argument values. This methods uses the ConstructorArg to retrieve the argument values
        Type Parameters:
        T - the sourceObj object type
        K - the target object type
        Parameters:
        sourceObj - sourceObj the source object
        targetClass - the destination object class
        constructor - the all args constructor
        breadcrumb - the full path of the current field starting from his ancestor
        Returns:
        a list containing the values for the destination constructor.
        Throws:
        InvalidBeanException - InvalidBeanException if there is an error while retrieving the constructor args parameter
      • setDefaultValueForMissingField

        public final BeanTransformer 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.
        Specified by:
        setDefaultValueForMissingField in interface BeanTransformer
        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 BeanTransformer instance
      • setDefaultValueForMissingPrimitiveField

        public BeanTransformer setDefaultValueForMissingPrimitiveField​(boolean useDefaultValue)
        It allows to enable/disable the set of the default value for primitive types in case they are null.
        Specified by:
        setDefaultValueForMissingPrimitiveField in interface BeanTransformer
        Parameters:
        useDefaultValue - if true the default value for the primitive type is set. By default it's true.
        Returns:
        the BeanTransformer instance
      • setFlatFieldNameTransformation

        public final BeanTransformer setFlatFieldNameTransformation​(boolean useFlatTransformation)
        It allows to configure the transformer in order to apply a transformation function on all fields matching the given name without keeping in consideration their full path. If set to true the default value is set, if false if it raises a: MissingFieldException in case of missing fields.
        Specified by:
        setFlatFieldNameTransformation in interface BeanTransformer
        Parameters:
        useFlatTransformation - indicates if the transformer function has to be performed on all fields matching the given name without keeping in consideration their full path.
        Returns:
        the BeanTransformer instance
      • setPrimitiveTypeConversionEnabled

        public BeanTransformer setPrimitiveTypeConversionEnabled​(boolean primitiveTypeConversionEnabled)
        It allows to enable/disable the automatic conversion of primitive types.
        Specified by:
        setPrimitiveTypeConversionEnabled in interface BeanTransformer
        Parameters:
        primitiveTypeConversionEnabled - if true primitive types are transformed automatically. By default it's false.
        Returns:
        the BeanTransformer instance
      • setCustomBuilderTransformationEnabled

        public BeanTransformer setCustomBuilderTransformationEnabled​(boolean customBuilderTransformationEnabled)
        It allows to enable/disable the transformation of Java Bean with a custom Builder pattern.
        Specified by:
        setCustomBuilderTransformationEnabled in interface BeanTransformer
        Parameters:
        customBuilderTransformationEnabled - if true Java Beans with a custom Builder pattern are transformed automatically. By default it's false.
        Returns:
        the BeanTransformer instance
      • transform

        public final <T,​K> K transform​(T sourceObj,
                                             java.lang.Class<? extends K> targetClass)
        Copies all properties from an object to a new one.
        Specified by:
        transform in interface BeanTransformer
        Type Parameters:
        T - the Source object type
        K - the target object type
        Parameters:
        sourceObj - the source object
        targetClass - the destination object class
        Returns:
        a copy of the source object into the destination object
      • transform

        public final <T,​K> void transform​(T sourceObj,
                                                K targetObject)
        Copies all properties from an object to a new one.
        Specified by:
        transform in interface BeanTransformer
        Type Parameters:
        T - the Source object type
        K - the target object type
        Parameters:
        sourceObj - the source object
        targetObject - the destination object
      • skipTransformationForField

        public BeanTransformer skipTransformationForField​(java.lang.String... fieldName)
        Allows to specify all the fields for which the transformation have to be skipped.
        Specified by:
        skipTransformationForField in interface BeanTransformer
        Parameters:
        fieldName - the destination object's field(s) name that have to be skipped
        Returns:
        the BeanTransformer instance