From - The type to convert values from.To - The type to convert values to.public interface Converter<From,To>
Converter is used to convert (transform, translate, project,
evaluate, ...) values from one form into another.
Common use cases of a Converter include:
Converter<String, UUID> uuidConverter = new Converter<String, UUID> () {
@Override
public UUID convert(String uuidString) throws ConverterException {
try{
return UUID.fromString(uuidString);
} catch (IllegalArgumentException e) {
throw new ConverterException(e);
}
}
};
Converter<Entity, Integer> idConverter = new Converter<Entity, Integer> () {
@Override
public Integer convert(Entity entity) throws ConverterException {
return entity.getId();
}
};
| Modifier and Type | Method and Description |
|---|---|
To |
convert(From from)
Called to convert a given value.
|
To convert(From from) throws ConversionException
Implementers should catch any exception and wrap them in a
ConversionException.
Depending on the use case, if the given value null, the
Converter should return null.
It lies in the responsibility of the caller, to handle unwanted
null-values by replacing them with a sensible default value or
throwing an appropriate ConversionException.
from - The value to be converted.ConversionException - If the conversion failed.Copyright © 2015–2017 Markenwerk – Gesellschaft für markenbildende Maßnahmen mbH. All rights reserved.