Package io.micronaut.core.convert
Class DefaultMutableConversionService
java.lang.Object
io.micronaut.core.convert.DefaultMutableConversionService
- All Implemented Interfaces:
ConversionService
,MutableConversionService
The default conversion service. Handles basic type conversion operations.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Fields inherited from interface io.micronaut.core.convert.ConversionService
SHARED
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<S,
T> void addConverter
(Class<S> sourceType, Class<T> targetType, TypeConverter<S, T> typeConverter) Adds a type converter.<S,
T> void addConverter
(Class<S> sourceType, Class<T> targetType, Function<S, T> function) Adds a type converter.<S,
T> boolean canConvert
(Class<S> sourceType, Class<T> targetType) Return whether the given source type is convertible to the given target type.<T> Optional<T>
convert
(Object object, Class<T> targetType, ConversionContext context) Attempts to convert the given object to the given target type.protected <T> TypeConverter<Object,
T> findTypeConverter
(Class<?> sourceType, Class<T> targetType, String formattingAnnotation) Find the type converter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.core.convert.ConversionService
convert, convert, convert, convertRequired, convertRequired
-
Constructor Details
-
DefaultMutableConversionService
public DefaultMutableConversionService()Constructor.
-
-
Method Details
-
convert
Description copied from interface:ConversionService
Attempts to convert the given object to the given target type. If conversion fails or is not possible an emptyOptional
is returned.- Specified by:
convert
in interfaceConversionService
- Type Parameters:
T
- The generic type- Parameters:
object
- The object to converttargetType
- The target typecontext
- The conversion context- Returns:
- The optional
-
canConvert
Description copied from interface:ConversionService
Return whether the given source type is convertible to the given target type.- Specified by:
canConvert
in interfaceConversionService
- Type Parameters:
S
- The generic source typeT
- The target source type- Parameters:
sourceType
- The source typetargetType
- The target type- Returns:
- True if it can be converted
-
addConverter
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, TypeConverter<S, T> typeConverter) Description copied from interface:MutableConversionService
Adds a type converter.- Specified by:
addConverter
in interfaceMutableConversionService
- Type Parameters:
S
- The source generic typeT
- The target generic type- Parameters:
sourceType
- The source typetargetType
- The target typetypeConverter
- The type converter
-
addConverter
Description copied from interface:MutableConversionService
Adds a type converter.- Specified by:
addConverter
in interfaceMutableConversionService
- Type Parameters:
S
- The source generic typeT
- The target generic type- Parameters:
sourceType
- The source typetargetType
- The target typefunction
- The type converter
-
findTypeConverter
protected <T> TypeConverter<Object,T> findTypeConverter(Class<?> sourceType, Class<T> targetType, String formattingAnnotation) Find the type converter.- Type Parameters:
T
- Generic type- Parameters:
sourceType
- sourceTypetargetType
- targetTypeformattingAnnotation
- formattingAnnotation- Returns:
- type converter
-