Top Description Inners Fields Constructors Methods
org.springframework.core.convert.support

public Class GenericConversionService

extends Object
implements ConfigurableConversionService
Class Inheritance
All Implemented Interfaces
org.springframework.core.convert.support.ConfigurableConversionService, org.springframework.core.convert.converter.ConverterRegistry, org.springframework.core.convert.ConversionService
Known Direct Subclasses
org.springframework.core.convert.support.DefaultConversionService
Imports
java.util.ArrayList, .Collections, .Deque, .HashSet, .List, .Map, .Optional, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentLinkedDeque, .CopyOnWriteArraySet, org.springframework.core.DecoratingProxy, .ResolvableType, org.springframework.core.convert.ConversionFailedException, .ConversionService, .ConverterNotFoundException, .TypeDescriptor, org.springframework.core.convert.converter.ConditionalConverter, .ConditionalGenericConverter, .Converter, .ConverterFactory, .ConverterRegistry, .GenericConverter, .GenericConverter.ConvertiblePair, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ConcurrentReferenceHashMap, .StringUtils

Base ConversionService implementation suitable for use in most environments. Indirectly implements ConverterRegistry as registration API through the ConfigurableConversionService interface.
Authors
Keith Donald, Juergen Hoeller, Chris Beams, Phillip Webb, David Haraburda
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
GenericConversionService.ConverterCacheKey

Key for use with the converter cache.

private class
private static class
GenericConversionService.Converters

Manages all converters registered with the service.

private static class
GenericConversionService.ConvertersForPair

Manages converters registered with a specific ConvertiblePair.

private static class
GenericConversionService.NoOpConverter

Internal converter that performs no operation.

Field Summary

Modifier and TypeField and Description
private final Map<GenericConversionService.ConverterCacheKey, GenericConverter>
private final GenericConversionService.Converters
private static final GenericConverter
NO_MATCH

Used as a cache entry when no converter is available.

private static final GenericConverter
NO_OP_CONVERTER

General NO-OP converter used when conversion is not required.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addConverter(Converter<?, ?> converter)

Implements org.springframework.core.convert.converter.ConverterRegistry.addConverter.

Add a plain converter to this registry.
public <S, T> void
addConverter(Class<S> sourceType, Class<T> targetType, Converter<? super S, ? extends T> converter)

Implements org.springframework.core.convert.converter.ConverterRegistry.addConverter.

Add a plain converter to this registry.
public void
public void
addConverterFactory(ConverterFactory<?, ?> factory)

Implements org.springframework.core.convert.converter.ConverterRegistry.addConverterFactory.

Add a ranged converter factory to this registry.
private void
public boolean

Returns:

true if conversion can be bypassed; false otherwise
canBypassConvert
(TypeDescriptor
context about the source type to convert from (may be null if source is null)
sourceType
,
TypeDescriptor
context about the target type to convert to (required)
targetType
)

Return whether conversion between the source type and the target type can be bypassed.

public boolean
canConvert(Class<?>
the source type to convert from (may be null if source is null)
sourceType
,
Class<?>
the target type to convert to (required)
targetType
)

Implements org.springframework.core.convert.ConversionService.canConvert.

Return true if objects of sourceType can be converted to the targetType.
public boolean
canConvert(TypeDescriptor
context about the source type to convert from (may be null if source is null)
sourceType
,
TypeDescriptor
context about the target type to convert to (required)
targetType
)

Implements org.springframework.core.convert.ConversionService.canConvert.

Return true if objects of sourceType can be converted to the targetType.
public <T> T
convert(Object
the source object to convert (may be null)
source
,
Class<T>
the target type to convert to (required)
targetType
)

Implements org.springframework.core.convert.ConversionService.convert.

Convert the given source to the specified targetType.
public Object
convert(Object
the source object to convert (may be null)
source
,
TypeDescriptor
context about the source type to convert from (may be null if source is null)
sourceType
,
TypeDescriptor
context about the target type to convert to (required)
targetType
)

Implements org.springframework.core.convert.ConversionService.convert.

Convert the given source to the specified targetType.
protected Object

Returns:

the converted null object
convertNullSource
(TypeDescriptor
the source type to convert from
sourceType
,
TypeDescriptor
the target type to convert to
targetType
)

Template method to convert a null source.

protected GenericConverter

Returns:

the generic converter that will perform the conversion, or null if no suitable converter was found
getConverter
(TypeDescriptor
the source type to convert from
sourceType
,
TypeDescriptor
the target type to convert to
targetType
)

Hook method to look up the converter for a given sourceType/targetType pair.

protected GenericConverter

Returns:

the default generic converter that will perform the conversion
getDefaultConverter
(TypeDescriptor
the source type to convert from
sourceType
,
TypeDescriptor
the target type to convert to
targetType
)

Return the default converter if no converter is found for the given sourceType/targetType pair.

private ResolvableType[]
getRequiredTypeInfo(Class<?> converterClass, Class<?> genericIfc)

private Object
private Object
handleResult(TypeDescriptor sourceType, TypeDescriptor targetType, Object result)

private void
public void
removeConvertible(Class<?>
the source type
sourceType
,
Class<?>
the target type
targetType
)

Implements org.springframework.core.convert.converter.ConverterRegistry.removeConvertible.

Remove any converters from sourceType to targetType.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait