Package com.vaadin.data.util.converter
Interface Converter<PRESENTATION,MODEL>
-
- Type Parameters:
PRESENTATION
- The presentation type. Must be compatible with whatgetPresentationType()
returns.MODEL
- The model type. Must be compatible with whatgetModelType()
returns.
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractStringToNumberConverter
,DateToLongConverter
,DateToSqlDateConverter
,DesignDateConverter
,DesignEnumConverter
,DesignObjectConverter
,DesignResourceConverter
,DesignShortcutActionConverter
,DesignTimeZoneConverter
,DesignToStringConverter
,ReverseConverter
,StringToBigDecimalConverter
,StringToBigIntegerConverter
,StringToBooleanConverter
,StringToByteConverter
,StringToCollectionConverter
,StringToDateConverter
,StringToDoubleConverter
,StringToEnumConverter
,StringToFloatConverter
,StringToIntegerConverter
,StringToLongConverter
,StringToShortConverter
public interface Converter<PRESENTATION,MODEL> extends Serializable
Interface that implements conversion between a model and a presentation type.Typically
convertToPresentation(Object, Class, Locale)
andconvertToModel(Object, Class, Locale)
should be symmetric so that chaining these together returns the original result for all input but this is not a requirement.Converters must not have any side effects (never update UI from inside a converter).
All Converters must be stateless and thread safe.
If conversion of a value fails, a
Converter.ConversionException
is thrown.- Since:
- 7.0
- Author:
- Vaadin Ltd.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Converter.ConversionException
An exception that signals that the value passed toconvertToPresentation(Object, Class, Locale)
orconvertToModel(Object, Class, Locale)
could not be converted.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MODEL
convertToModel(PRESENTATION value, Class<? extends MODEL> targetType, Locale locale)
Converts the given value from target type to source type.PRESENTATION
convertToPresentation(MODEL value, Class<? extends PRESENTATION> targetType, Locale locale)
Converts the given value from source type to target type.Class<MODEL>
getModelType()
The source type of the converter.Class<PRESENTATION>
getPresentationType()
The target type of the converter.
-
-
-
Method Detail
-
convertToModel
MODEL convertToModel(PRESENTATION value, Class<? extends MODEL> targetType, Locale locale) throws Converter.ConversionException
Converts the given value from target type to source type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingconvertToPresentation(Object, Class, Locale)
andconvertToModel(Object, Class, Locale)
should return the original value.- Parameters:
value
- The value to convert, compatible with the target type. Can be nulltargetType
- The requested type of the return valuelocale
- The locale to use for conversion. Can be null.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException
- If the value could not be converted
-
convertToPresentation
PRESENTATION convertToPresentation(MODEL value, Class<? extends PRESENTATION> targetType, Locale locale) throws Converter.ConversionException
Converts the given value from source type to target type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingconvertToPresentation(Object, Class, Locale)
andconvertToModel(Object, Class, Locale)
should return the original value.- Parameters:
value
- The value to convert, compatible with the target type. Can be nulltargetType
- The requested type of the return valuelocale
- The locale to use for conversion. Can be null.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException
- If the value could not be converted
-
getModelType
Class<MODEL> getModelType()
The source type of the converter. Values of this type can be passed toconvertToPresentation(Object, Class, Locale)
.- Returns:
- The source type
-
getPresentationType
Class<PRESENTATION> getPresentationType()
The target type of the converter. Values of this type can be passed toconvertToModel(Object, Class, Locale)
.- Returns:
- The target type
-
-