Package com.github.dozermapper.core
Class DozerConverter<A,B>
- java.lang.Object
-
- com.github.dozermapper.core.DozerConverter<A,B>
-
- All Implemented Interfaces:
ConfigurableCustomConverter,CustomConverter
public abstract class DozerConverter<A,B> extends Object implements ConfigurableCustomConverter
This class should be extended in order to implement new Custom Converters for value transformation.
-
-
Constructor Summary
Constructors Constructor Description DozerConverter(Class<A> prototypeA, Class<B> prototypeB)Defines two types, which will take part transformation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Objectconvert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass)AconvertFrom(B source)Converts the source field to the destination field and return the resulting destination valueabstract AconvertFrom(B source, A destination)Converts the source field to the destination field and return the resulting destination valueBconvertTo(A source)Converts the source field to the destination field and return the resulting destination value.abstract BconvertTo(A source, B destination)Converts the source field to the destination field and return the resulting destination value.StringgetParameter()Retrieves the static parameter configured for this particular converter instance.voidsetParameter(String parameter)Sets the configured parameter value for this converter instance.
-
-
-
Constructor Detail
-
DozerConverter
public DozerConverter(Class<A> prototypeA, Class<B> prototypeB)
Defines two types, which will take part transformation. As Dozer supports bi-directional mapping it is not known which of the classes is source and which is destination. It will be decided in runtime.- Parameters:
prototypeA- type oneprototypeB- type two
-
-
Method Detail
-
convert
public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass)
- Specified by:
convertin interfaceCustomConverter
-
convertTo
public abstract B convertTo(A source, B destination)
Converts the source field to the destination field and return the resulting destination value.- Parameters:
source- the value of the source fielddestination- the current value of the destination field (or null)- Returns:
- the resulting value for the destination field
-
convertTo
public B convertTo(A source)
Converts the source field to the destination field and return the resulting destination value.- Parameters:
source- the value of the source field- Returns:
- the resulting value for the destination field
-
convertFrom
public abstract A convertFrom(B source, A destination)
Converts the source field to the destination field and return the resulting destination value- Parameters:
source- the value of the source fielddestination- the current value of the destination field (or null)- Returns:
- the resulting value for the destination field
-
convertFrom
public A convertFrom(B source)
Converts the source field to the destination field and return the resulting destination value- Parameters:
source- the value of the source field- Returns:
- the resulting value for the destination field
-
setParameter
public void setParameter(String parameter)
Sets the configured parameter value for this converter instance. Should be called by Dozer internally before actual mapping.- Specified by:
setParameterin interfaceConfigurableCustomConverter- Parameters:
parameter- configured parameter value
-
getParameter
public String getParameter()
Retrieves the static parameter configured for this particular converter instance. It is not advisable to call this method from converter constructor as the parameter is not yet there.- Returns:
- parameter value
- Throws:
IllegalStateException- if parameter has not been set yet.
-
-