addConverter

Add a plain converter to this registry.
The convertible sourceType/targetType pair is specified explicitly.
Allows for a Converter to be reused for multiple distinct pairs without having to create a Converter class for each pair.

canConvert

Returns true if objects of sourceType can be converted to targetType.
If this method returns true, it means ConversionService.convert(Object, Class) is capable of converting an instance of sourceType to targetType.
Special note on collections, arrays, and maps types:
For conversion between collection, array, and map types, this method will return 'true'
even though a convert invocation may still generate a ConversionException if the underlying elements are not convertible.
Callers are expected to handle this exceptional case when working with collections and maps.

canConvert

Returns true if objects of sourceType can be converted to the targetType.
The TypeDescriptors provide additional context about the source and target locations where conversion would occur, often object fields or property locations.
If this method returns true, it means ConversionService.convert(Object, TypeDescriptor, TypeDescriptor) is capable of converting an instance of sourceType to targetType.
Special note on collections, arrays, and maps types:
For conversion between collection, array, and map types, this method will return 'true'
even though a convert invocation may still generate a ConversionException if the underlying elements are not convertible.
Callers are expected to handle this exceptional case when working with collections and maps.

canBypassConvert

Returns true if conversion between the sourceType and targetType can be bypassed.
More precisely this method will return true if objects of sourceType can be
converted to the targetType by returning the source object unchanged.

Parameters:

sourceType - context about the source type to convert from (may be null if source is null)

getConverter

Hook method to lookup the converter for a given sourceType/targetType pair.
First queries this ConversionService's converter cache.
On a cache miss, then performs an exhaustive search for a matching converter.
If no converter matches, returns the default converter.
Subclasses may override.

Parameters:

sourceType - the source type to convert from

targetType - the target type to convert to

Returns:

the generic converter that will perform the conversion, or null if
no suitable converter was found

getDefaultConverter

Return the default converter if no converter is found for the given sourceType/targetType pair.
Returns a NO_OP Converter if the sourceType is assignable to the targetType.
Returns null otherwise, indicating no suitable converter could be found.
Subclasses may override.