Package io.micronaut.core.convert
Class DefaultConversionService
- java.lang.Object
-
- io.micronaut.core.convert.DefaultConversionService
-
- All Implemented Interfaces:
ConversionService<DefaultConversionService>
public class DefaultConversionService extends java.lang.Object implements ConversionService<DefaultConversionService>
The default conversion service. Handles basic type conversion operations.- Since:
- 1.0
-
-
Field Summary
-
Fields inherited from interface io.micronaut.core.convert.ConversionService
SHARED
-
-
Constructor Summary
Constructors Constructor Description DefaultConversionService()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <S,T>
DefaultConversionServiceaddConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, TypeConverter<S,T> typeConverter)
Adds a type converter.<S,T>
DefaultConversionServiceaddConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.util.function.Function<S,T> function)
Adds a type converter.<S,T>
booleancanConvert(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
Return whether the given source type is convertible to the given target type.<T> java.util.Optional<T>
convert(java.lang.Object object, java.lang.Class<T> targetType, ConversionContext context)
Attempts to convert the given object to the given target type.protected <T> TypeConverter
findTypeConverter(java.lang.Class<?> sourceType, java.lang.Class<T> targetType, java.lang.String formattingAnnotation)
Find the type converter.protected void
registerDefaultConverters()
Default Converters.void
reset()
Reset internal state.-
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
-
-
-
-
Method Detail
-
convert
public <T> java.util.Optional<T> convert(java.lang.Object object, java.lang.Class<T> targetType, ConversionContext context)
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<DefaultConversionService>
- Type Parameters:
T
- The generic type- Parameters:
object
- The object to converttargetType
- The target typecontext
- The conversion context- Returns:
- The optional
-
canConvert
public <S,T> boolean canConvert(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
Description copied from interface:ConversionService
Return whether the given source type is convertible to the given target type.- Specified by:
canConvert
in interfaceConversionService<DefaultConversionService>
- 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> DefaultConversionService addConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, TypeConverter<S,T> typeConverter)
Description copied from interface:ConversionService
Adds a type converter.- Specified by:
addConverter
in interfaceConversionService<DefaultConversionService>
- Type Parameters:
S
- The source generic typeT
- The target generic type- Parameters:
sourceType
- The source typetargetType
- The target typetypeConverter
- The type converter- Returns:
- This conversion service
-
addConverter
public <S,T> DefaultConversionService addConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.util.function.Function<S,T> function)
Description copied from interface:ConversionService
Adds a type converter.- Specified by:
addConverter
in interfaceConversionService<DefaultConversionService>
- Type Parameters:
S
- The source generic typeT
- The target generic type- Parameters:
sourceType
- The source typetargetType
- The target typefunction
- The type converter- Returns:
- This conversion service
-
reset
@Internal public void reset()
Reset internal state.- Since:
- 3.5.3
-
registerDefaultConverters
protected void registerDefaultConverters()
Default Converters.
-
findTypeConverter
protected <T> TypeConverter findTypeConverter(java.lang.Class<?> sourceType, java.lang.Class<T> targetType, java.lang.String formattingAnnotation)
Find the type converter.- Type Parameters:
T
- Generic type- Parameters:
sourceType
- sourceTypetargetType
- targetTypeformattingAnnotation
- formattingAnnotation- Returns:
- type converter
-
-