Class MapperUtils


  • @Component
    public class MapperUtils
    extends Object
    MapperUtils class provides methods to map or copy values from source object to destination object.
    Since:
    1.0.0
    Author:
    Bal Vikash Sharma, Urvil Joshi
    See Also:
    MapperUtils
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <S,​D>
      D
      map​(S source, D destination)
      This method map the values from source to destination if name and type of the fields inside the given parameters are same.If any of the parameters are null this method return null.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly.
      static <S,​D>
      D
      map​(S source, D destination, Boolean mapNullValues)
      This method map the values from source to destination if name and type of the fields inside the given parameters are same.If any of the parameters are null this method return null.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly.
      static <S,​D>
      D
      map​(S source, Class<D> destinationClass)
      This method takes source and destinationClass, take all values from source and create an object of destinationClass and map all the values from source to destination if field name and type is same.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly.If any Collection type or Entity type field is their then only matched name fields value will be set but not the embedded IDs and super class values.
      static <S,​D>
      List<D>
      mapAll​(Collection<S> sourceList, Class<D> destinationClass)
      This method takes sourceList and destinationClass, take all values from source and create an object of destinationClass and map all the values from source to destination if field name and type is same.
      static List<SearchAuthPolicy> mapAuthPolicySearch​(List<AuthPolicy> authPolicies)  
      static <S,​D>
      void
      mapFieldValues​(S source, D destination)
      This method map values of source object to destination object.
      static LocalDateTime parseToLocalDateTime​(String dateTime)
      Parse a date string of pattern UTC_DATETIME_PATTERN into LocalDateTime
      static <S,​D>
      void
      setBaseFieldValue​(S source, D destination)
      Map values from BaseEntity class source object to destination or vice versa and this method will be used to map BaseEntity values from entity to entity.
    • Method Detail

      • parseToLocalDateTime

        public static LocalDateTime parseToLocalDateTime​(String dateTime)
        Parse a date string of pattern UTC_DATETIME_PATTERN into LocalDateTime
        Parameters:
        dateTime - of type String of pattern UTC_DATETIME_PATTERN
        Returns:
        a LocalDateTime of given pattern
      • map

        public static <S,​D> D map​(S source,
                                        D destination,
                                        Boolean mapNullValues)
        This method map the values from source to destination if name and type of the fields inside the given parameters are same.If any of the parameters are null this method return null.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly. If any Collection type or Entity type field is their then only matched name fields value will be set but not the embedded IDs and super class values.
        Type Parameters:
        S - is a type parameter
        D - is a type parameter
        Parameters:
        source - which value is going to be mapped
        destination - where values is going to be mapped
        mapNullValues - by default marked as true so, it will map null values but if marked as false then null values will be ignored
        Returns:
        the destination object
        Throws:
        NullPointerException - if either source or destination is null
      • map

        public static <S,​D> D map​(S source,
                                        D destination)
        This method map the values from source to destination if name and type of the fields inside the given parameters are same.If any of the parameters are null this method return null.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly. If any Collection type or Entity type field is their then only matched name fields value will be set but not the embedded IDs and super class values.
        Type Parameters:
        S - is a type parameter
        D - is a type parameter
        Parameters:
        source - which value is going to be mapped
        destination - where values is going to be mapped
        Returns:
        the destination object
        Throws:
        NullPointerException - if either source or destination is null
      • map

        public static <S,​D> D map​(S source,
                                        Class<D> destinationClass)
        This method takes source and destinationClass, take all values from source and create an object of destinationClass and map all the values from source to destination if field name and type is same.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly.If any Collection type or Entity type field is their then only matched name fields value will be set but not the embedded IDs and super class values.
        Type Parameters:
        S - is a type parameter
        D - is a type parameter
        Parameters:
        source - which value is going to be mapped
        destinationClass - where values is going to be mapped
        Returns:
        the object of destinationClass
        Throws:
        io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException - if exception occur during creating of destinationClass object
        NullPointerException - if either source or destinationClass is null
      • mapAll

        public static <S,​D> List<D> mapAll​(Collection<S> sourceList,
                                                 Class<D> destinationClass)
        This method takes sourceList and destinationClass, take all values from source and create an object of destinationClass and map all the values from source to destination if field name and type is same.
        Type Parameters:
        S - is a type parameter
        D - is a type parameter
        Parameters:
        sourceList - which value is going to be mapped
        destinationClass - where values is going to be mapped
        Returns:
        list of destinationClass objects
        Throws:
        io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException - if exception occur during creating of destinationClass object
        NullPointerException - if either sourceList or destinationClass is null
      • mapFieldValues

        public static <S,​D> void mapFieldValues​(S source,
                                                      D destination)
        This method map values of source object to destination object. It will map field values having same name and same type for the fields. It will not map any field which is static or final.It will simply ignore those values.
        Type Parameters:
        S - is a type parameter
        D - is a type parameter
        Parameters:
        source - is any object which should not be null and have data which is going to be copied
        destination - is an object in which source field values is going to be matched
        Throws:
        io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException - if error raised during mapping values
        NullPointerException - if either source or destination is null
      • setBaseFieldValue

        public static <S,​D> void setBaseFieldValue​(S source,
                                                         D destination)
        Map values from BaseEntity class source object to destination or vice versa and this method will be used to map BaseEntity values from entity to entity. Like when both source and destination are object which extends BaseEntity.
        Type Parameters:
        S - is a type parameter
        D - is a type parameter
        Parameters:
        source - which value is going to be mapped
        destination - where values is going to be mapped