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> void addInternalConverter
(Class<S> sourceType, Class<T> targetType, TypeConverter<S, T> typeConverter) Add internal converter.<S,
T> void addInternalConverter
(Class<S> sourceType, Class<T> targetType, Function<S, T> function) Add internal converter.<S,
T> boolean canConvert
(Class<S> sourceType, Class<T> targetType) Return whether the given source type is convertible to the given target type.<S,
T> Optional<T> convert
(S object, Class<? super S> sourceType, Class<T> targetType, ConversionContext context) Attempts to convert the given object to the given target type from the given source type.protected <T> TypeConverter<Object,
T> findTypeConverter
(Class<?> sourceType, Class<T> targetType, String formattingAnnotation) Find the type converter.void
Register converters using the internal mutable conversion service.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, convert, convert, convertRequired, convertRequired, convertRequired
-
Constructor Details
-
DefaultMutableConversionService
public DefaultMutableConversionService()Constructor.
-
-
Method Details
-
convert
public <S,T> Optional<T> convert(S object, Class<? super S> sourceType, Class<T> targetType, ConversionContext context) Description copied from interface:ConversionService
Attempts to convert the given object to the given target type from the given source type. If conversion fails or is not possible an emptyOptional
is returned.- Specified by:
convert
in interfaceConversionService
- Type Parameters:
S
- The source typeT
- The target type- Parameters:
object
- The object to convertsourceType
- The source typetargetType
- 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
-
addInternalConverter
@Internal public <S,T> void addInternalConverter(Class<S> sourceType, Class<T> targetType, TypeConverter<S, T> typeConverter) Add internal converter.- Type Parameters:
S
- The source typeT
- The target type- Parameters:
sourceType
- The source typetargetType
- The target typetypeConverter
- The 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
-
addInternalConverter
@Internal public <S,T> void addInternalConverter(Class<S> sourceType, Class<T> targetType, Function<S, T> function) Add internal converter.- Type Parameters:
S
- The source typeT
- The target type- Parameters:
sourceType
- The source typetargetType
- The target typefunction
- The converter function
-
registerInternalTypeConverters
Register converters using the internal mutable conversion service.- Parameters:
registrars
- The converters- Since:
- 4.2.0
-
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
-