Package org.springframework.beans

# Class TypeConverterSupport

java.lang.Object
org.springframework.beans.PropertyEditorRegistrySupport
org.springframework.beans.TypeConverterSupport

All Implemented Interfaces:
  `PropertyEditorRegistry`, `TypeConverter`

Direct Known Subclasses:
  `AbstractPropertyAccessor`, `SimpleTypeConverter`

public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport implements TypeConverter
Base implementation of the `TypeConverter` interface, using a package-private delegate. Mainly serves as base class for `BeanWrapperImpl`.

Since:
  3.2
Author:
  Juergen Hoeller
See Also:
  - `SimpleTypeConverter`

## Constructor Summary

Constructors
Constructor
Description
`TypeConverterSupport()`

## Method Summary

Modifier and Type
Method
Description
`<T> T`
`convertIfNecessary(Object value, Class<T> requiredType)`
Convert the value to the required type (if necessary from a String).
`<T> T`
`convertIfNecessary(Object value, Class<T> requiredType, Field field)`
Convert the value to the required type (if necessary from a String).
`<T> T`
`convertIfNecessary(Object value, Class<T> requiredType, org.springframework.core.convert.TypeDescriptor typeDescriptor)`
Convert the value to the required type (if necessary from a String).
`<T> T`
`convertIfNecessary(Object value, Class<T> requiredType, org.springframework.core.MethodParameter methodParam)`
Convert the value to the required type (if necessary from a String).

### Methods inherited from class org.springframework.beans.PropertyEditorRegistrySupport

`copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, getPropertyType, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, setDefaultEditorRegistrar, useConfigValueEditors`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### TypeConverterSupport

public TypeConverterSupport()

## Method Details

### convertIfNecessary

@Nullable public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException
Description copied from interface: `TypeConverter`
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, or a Spring Converter in a ConversionService.

Specified by:
  `convertIfNecessary` in interface `TypeConverter`
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()`
  - `ConversionService`
  - `Converter`

### convertIfNecessary

@Nullable public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable org.springframework.core.MethodParameter methodParam) throws TypeMismatchException
Description copied from interface: `TypeConverter`
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, or a Spring Converter in a ConversionService.

Specified by:
  `convertIfNecessary` in interface `TypeConverter`
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()`
  - `ConversionService`
  - `Converter`

### convertIfNecessary

@Nullable public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field) throws TypeMismatchException
Description copied from interface: `TypeConverter`
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, or a Spring Converter in a ConversionService.

Specified by:
  `convertIfNecessary` in interface `TypeConverter`
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)
  `field` - the reflective field 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()`
  - `ConversionService`
  - `Converter`

### convertIfNecessary

@Nullable public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable org.springframework.core.convert.TypeDescriptor typeDescriptor) throws TypeMismatchException
Description copied from interface: `TypeConverter`
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, or a Spring Converter in a ConversionService.

Specified by:
  `convertIfNecessary` in interface `TypeConverter`
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)
  `typeDescriptor` - the type descriptor to use (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()`
  - `ConversionService`
  - `Converter`