Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.beans
Interface TypeConverter

All Known Subinterfaces:
  BeanWrapper, ConfigurablePropertyAccessor

All Known Implementing Classes:
  AbstractPropertyAccessor, BeanWrapperImpl, DataBinder, DirectFieldAccessor, ExtendedServletRequestDataBinder, PortletRequestDataBinder, ServletRequestDataBinder, SimpleTypeConverter, WebDataBinder, WebRequestDataBinder

    public interface TypeConverter

Interface that defines type conversion methods. Typically (but not necessarily) implemented in conjunction with the PropertyEditorRegistry interface.

Since:
  2.0
Author:
  Juergen Hoeller
See Also:
  `PropertyEditorRegistry`, `SimpleTypeConverter`, `BeanWrapperImpl`

Method Summary
`
`<T> T`
` | `convertIfNecessary(java.lang.Object value, java.lang.Class<T> requiredType)` Convert the value to the required type (if necessary from a String).
`
`<T> T`
` | `convertIfNecessary(java.lang.Object value, java.lang.Class<T> requiredType, MethodParameter methodParam)` Convert the value to the required type (if necessary from a String).

Method Detail

### convertIfNecessary

    <T> T convertIfNecessary(java.lang.Object value,
                             java.lang.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 `setAsText` method of the PropertyEditor class. Note that a PropertyEditor must be registered for the given class for this to work; this is a standard JavaBeans API. A number of PropertyEditors are automatically registered.

  Parameters:
    `value` - the value to convert
    `requiredType` - the type we must convert to (or `null` if 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:
    `PropertyEditor.setAsText(String)`, `PropertyEditor.getValue()`

### convertIfNecessary

    <T> T convertIfNecessary(java.lang.Object value,
                             java.lang.Class<T> requiredType,
                             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 `setAsText` method of the PropertyEditor class. Note that a PropertyEditor must be registered for the given class for this to work; this is a standard JavaBeans API. A number of PropertyEditors are automatically registered.

  Parameters:
    `value` - the value to convert
    `requiredType` - the type we must convert to (or `null` if 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 be `null`)
  Returns:
    the new value, possibly the result of type conversion
  Throws:
    `TypeMismatchException` - if type conversion failed
  See Also:
    `PropertyEditor.setAsText(String)`, `PropertyEditor.getValue()`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD