Interface TypeConverter
- All Known Subinterfaces:
BeanWrapper, ConfigurablePropertyAccessor
- All Known Implementing Classes:
AbstractNestablePropertyAccessor, AbstractPropertyAccessor, BeanWrapperImpl, DataBinder, DirectFieldAccessor, ExtendedServletRequestDataBinder, ExtendedWebExchangeDataBinder, ServletRequestDataBinder, SimpleTypeConverter, TypeConverterSupport, WebDataBinder, WebExchangeDataBinder, WebRequestDataBinder
PropertyEditorRegistry interface.
Note: Since TypeConverter implementations are typically based on
PropertyEditors which aren't thread-safe,
TypeConverters themselves are not to be considered as thread-safe either.
- Since:
- 2.0
- Author:
- Juergen Hoeller
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T> @nullable TconvertIfNecessary(@nullable Object value, @nullable Class<T> requiredType) Convert the value to the required type (if necessary from a String).<T> @nullable TConvert the value to the required type (if necessary from a String).<T> @nullable TconvertIfNecessary(@nullable Object value, @nullable Class<T> requiredType, @nullable MethodParameter methodParam) Convert the value to the required type (if necessary from a String).default <T> @nullable TconvertIfNecessary(@nullable Object value, @nullable Class<T> requiredType, @nullable TypeDescriptor typeDescriptor) Convert the value to the required type (if necessary from a String).
-
Method Details
-
convertIfNecessary
<T> @nullable T convertIfNecessary(@nullable Object value, @nullable Class<T> requiredType) throws TypeMismatchException Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsTextmethod of the PropertyEditor class, or a Spring Converter in a ConversionService.- Parameters:
value- the value to convertrequiredType- the type we must convert to (ornullif not known, for example in case of a collection element)- Returns:
- the new value, possibly the result of type conversion
- Throws:
TypeMismatchException- if type conversion failed- See Also:
-
convertIfNecessary
<T> @nullable T convertIfNecessary(@nullable Object value, @nullable Class<T> requiredType, @nullable MethodParameter methodParam) throws TypeMismatchException Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsTextmethod of the PropertyEditor class, or a Spring Converter in a ConversionService.- Parameters:
value- the value to convertrequiredType- the type we must convert to (ornullif not known, for example in case of a collection element)methodParam- the method parameter that is the target of the conversion (for analysis of generic types; may benull)- Returns:
- the new value, possibly the result of type conversion
- Throws:
TypeMismatchException- if type conversion failed- See Also:
-
convertIfNecessary
<T> @nullable T convertIfNecessary(@nullable Object value, @nullable Class<T> requiredType, @nullable Field field) throws TypeMismatchException Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsTextmethod of the PropertyEditor class, or a Spring Converter in a ConversionService.- Parameters:
value- the value to convertrequiredType- the type we must convert to (ornullif not known, for example in case of a collection element)field- the reflective field that is the target of the conversion (for analysis of generic types; may benull)- Returns:
- the new value, possibly the result of type conversion
- Throws:
TypeMismatchException- if type conversion failed- See Also:
-
convertIfNecessary
default <T> @nullable T convertIfNecessary(@nullable Object value, @nullable Class<T> requiredType, @nullable TypeDescriptor typeDescriptor) throws TypeMismatchException Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsTextmethod of the PropertyEditor class, or a Spring Converter in a ConversionService.- Parameters:
value- the value to convertrequiredType- the type we must convert to (ornullif not known, for example in case of a collection element)typeDescriptor- the type descriptor to use (may benull))- Returns:
- the new value, possibly the result of type conversion
- Throws:
TypeMismatchException- if type conversion failed- Since:
- 5.1.4
- See Also:
-