Interface ConversionService
- All Known Implementing Classes:
DefaultConversionService
,FacesConversionService
,GenericConversionService
public interface ConversionService
A service interface for retrieving type conversion executors. The returned command objects are thread-safe and may be
safely cached for use by client code.
Type converters convert from one type to another.
- Author:
- Keith Donald
-
Method Summary
Modifier and TypeMethodDescriptionexecuteConversion
(Object source, Class<?> targetClass) Execute a conversion of the source object provided to the specifiedtargetClass
executeConversion
(String converterId, Object source, Class<?> targetClass) Execute a conversion using the custom converter with the provided id.Class<?>
getClassForAlias
(String alias) Lookup a class by its well-known alias.getConversionExecutor
(Class<?> sourceClass, Class<?> targetClass) Return the default conversion executor capable of converting source objects of the specifiedsourceClass
to instances of thetargetClass
.getConversionExecutor
(String id, Class<?> sourceClass, Class<?> targetClass) Return the custom conversion executor capable of converting source objects of the specifiedsourceClass
to instances of thetargetClass
.org.springframework.core.convert.ConversionService
Return the underlying Spring ConversionService.
-
Method Details
-
executeConversion
Execute a conversion of the source object provided to the specifiedtargetClass
- Parameters:
source
- the source to convert from (may be null)targetClass
- the target class to convert to- Returns:
- the converted object, an instance of the
targetClass
- Throws:
ConversionException
- if an exception occurred during the conversion process
-
executeConversion
Execute a conversion using the custom converter with the provided id.- Parameters:
converterId
- the id of the custom converter, which must be registered with this conversion service and capable of converting to the target classsource
- the source to convert from (may be null)targetClass
- the target class to convert to- Returns:
- the converted object, an instance of the
targetClass
- Throws:
ConversionException
- if an exception occurred during the conversion process
-
getConversionExecutor
ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass) throws ConversionExecutorNotFoundException Return the default conversion executor capable of converting source objects of the specifiedsourceClass
to instances of thetargetClass
.The returned ConversionExecutor is thread-safe and may safely be cached for use in client code.
- Parameters:
sourceClass
- the source class to convert from (required)targetClass
- the target class to convert to (required)- Returns:
- the executor that can execute instance type conversion, never null
- Throws:
ConversionExecutorNotFoundException
- when no suitable conversion executor could be found
-
getConversionExecutor
ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass) throws ConversionExecutorNotFoundException Return the custom conversion executor capable of converting source objects of the specifiedsourceClass
to instances of thetargetClass
.The returned ConversionExecutor is thread-safe and may safely be cached for use in client code.
- Parameters:
id
- the id of the custom conversion executor (required)sourceClass
- the source class to convert from (required)targetClass
- the target class to convert to (required)- Returns:
- the executor that can execute instance type conversion, never null
- Throws:
ConversionExecutorNotFoundException
- when no suitable conversion executor could be found
-
getClassForAlias
Lookup a class by its well-known alias. For example,long
forjava.lang.Long
- Parameters:
alias
- the class alias- Returns:
- the class, or
null
if no alias exists
-
getDelegateConversionService
org.springframework.core.convert.ConversionService getDelegateConversionService()Return the underlying Spring ConversionService.- Returns:
- the conversion service
-