Package io.mosip.pms.common.util
Class MapperUtils
- java.lang.Object
-
- io.mosip.pms.common.util.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>
Dmap(S source, D destination)This method map the values fromsourcetodestinationif name and type of the fields inside the given parameters are same.If any of the parameters arenullthis method returnnull.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly.static <S,D>
Dmap(S source, D destination, Boolean mapNullValues)This method map the values fromsourcetodestinationif name and type of the fields inside the given parameters are same.If any of the parameters arenullthis method returnnull.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly.static <S,D>
Dmap(S source, Class<D> destinationClass)This method takessourceanddestinationClass, take all values from source and create an object ofdestinationClassand 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 anyCollectiontype 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 takessourceListanddestinationClass, take all values from source and create an object ofdestinationClassand 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>
voidmapFieldValues(S source, D destination)This method map values ofsourceobject todestinationobject.static LocalDateTimeparseToLocalDateTime(String dateTime)Parse a date string of pattern UTC_DATETIME_PATTERN intoLocalDateTimestatic <S,D>
voidsetBaseFieldValue(S source, D destination)Map values fromBaseEntityclass source object to destination or vice versa and this method will be used to mapBaseEntityvalues from entity to entity.
-
-
-
Method Detail
-
parseToLocalDateTime
public static LocalDateTime parseToLocalDateTime(String dateTime)
Parse a date string of pattern UTC_DATETIME_PATTERN intoLocalDateTime- Parameters:
dateTime- of typeStringof pattern UTC_DATETIME_PATTERN- Returns:
- a
LocalDateTimeof given pattern
-
map
public static <S,D> D map(S source, D destination, Boolean mapNullValues)This method map the values fromsourcetodestinationif name and type of the fields inside the given parameters are same.If any of the parameters arenullthis method returnnull.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly. If anyCollectiontype 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 parameterD- is a type parameter- Parameters:
source- which value is going to be mappeddestination- where values is going to be mappedmapNullValues- by default marked as true so, it will map null values but if marked as false then null values will be ignored- Returns:
- the
destinationobject - Throws:
NullPointerException- if eithersourceordestinationis null
-
map
public static <S,D> D map(S source, D destination)This method map the values fromsourcetodestinationif name and type of the fields inside the given parameters are same.If any of the parameters arenullthis method returnnull.This method internally check whether the source or destinationClass is DTO or an Entity type and map accordingly. If anyCollectiontype 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 parameterD- is a type parameter- Parameters:
source- which value is going to be mappeddestination- where values is going to be mapped- Returns:
- the
destinationobject - Throws:
NullPointerException- if eithersourceordestinationis null
-
map
public static <S,D> D map(S source, Class<D> destinationClass)This method takessourceanddestinationClass, take all values from source and create an object ofdestinationClassand 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 anyCollectiontype 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 parameterD- is a type parameter- Parameters:
source- which value is going to be mappeddestinationClass- 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 ofdestinationClassobjectNullPointerException- if eithersourceordestinationClassis null
-
mapAll
public static <S,D> List<D> mapAll(Collection<S> sourceList, Class<D> destinationClass)
This method takessourceListanddestinationClass, take all values from source and create an object ofdestinationClassand map all the values from source to destination if field name and type is same.- Type Parameters:
S- is a type parameterD- is a type parameter- Parameters:
sourceList- which value is going to be mappeddestinationClass- 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 ofdestinationClassobjectNullPointerException- if eithersourceListordestinationClassis null
-
mapFieldValues
public static <S,D> void mapFieldValues(S source, D destination)This method map values ofsourceobject todestinationobject. 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 parameterD- is a type parameter- Parameters:
source- is any object which should not be null and have data which is going to be copieddestination- 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 valuesNullPointerException- if eithersourceordestinationis null
-
setBaseFieldValue
public static <S,D> void setBaseFieldValue(S source, D destination)Map values fromBaseEntityclass source object to destination or vice versa and this method will be used to mapBaseEntityvalues from entity to entity. Like when bothsourceanddestinationare object which extendsBaseEntity.- Type Parameters:
S- is a type parameterD- is a type parameter- Parameters:
source- which value is going to be mappeddestination- where values is going to be mapped
-
mapAuthPolicySearch
public static List<SearchAuthPolicy> mapAuthPolicySearch(List<AuthPolicy> authPolicies)
-
-