Package io.micronaut.core.convert
Interface ConversionService
- All Known Subinterfaces:
Environment
,MutableConversionService
- All Known Implementing Classes:
DefaultEnvironment
,DefaultMutableConversionService
public interface ConversionService
A service for allowing conversion from one type to another.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ConversionService
The default shared conversion service. -
Method Summary
Modifier and TypeMethodDescription<S,
T> boolean canConvert
(Class<S> sourceType, Class<T> targetType) Return whether the given source type is convertible to the given target type.default <T> Optional<T>
convert
(Object object, ArgumentConversionContext<T> context) Attempts to convert the given object to the given target type.default <T> Optional<T>
Attempts to convert the given object to the given target type.default <T> Optional<T>
Attempts to convert the given object 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.default <T> T
convertRequired
(@Nullable Object value, Argument<T> argument) Convert the value to the given type.default <T> T
convertRequired
(@Nullable Object value, Class<T> type) Convert the value to the given type.default <T> T
convertRequired
(Object value, ArgumentConversionContext<T> context) Convert the value to the given type.
-
Field Details
-
SHARED
The default shared conversion service.
-
-
Method Details
-
convert
Attempts to convert the given object to the given target type. If conversion fails or is not possible an emptyOptional
is returned.- Type Parameters:
T
- The generic type- Parameters:
object
- The object to converttargetType
- The target typecontext
- The conversion context- Returns:
- The optional
-
canConvert
Return whether the given source type is convertible to the given target type.- 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
-
convert
Attempts to convert the given object to the given target type. If conversion fails or is not possible an emptyOptional
is returned.- Type Parameters:
T
- The generic type- Parameters:
object
- The object to converttargetType
- The target type- Returns:
- The optional
-
convert
Attempts to convert the given object to the given target type. If conversion fails or is not possible an emptyOptional
is returned.- Type Parameters:
T
- The generic type- Parameters:
object
- The object to converttargetType
- The target type- Returns:
- The optional
-
convert
Attempts to convert the given object to the given target type. If conversion fails or is not possible an emptyOptional
is returned.- Type Parameters:
T
- The generic type- Parameters:
object
- The object to convertcontext
- TheArgumentConversionContext
- Returns:
- The optional
-
convertRequired
Convert the value to the given type.- Type Parameters:
T
- The generic type- Parameters:
value
- The valuetype
- The type- Returns:
- The converted value
- Throws:
ConversionErrorException
- if the value cannot be converted- Since:
- 1.1.4
-
convertRequired
Convert the value to the given type.- Type Parameters:
T
- The generic type- Parameters:
value
- The valueargument
- The argument- Returns:
- The converted value
- Throws:
ConversionErrorException
- if the value cannot be converted- Since:
- 1.1.4
-
convertRequired
Convert the value to the given type.- Type Parameters:
T
- The generic type- Parameters:
value
- The valuecontext
- The conversion context- Returns:
- The converted value
- Throws:
ConversionErrorException
- if the value cannot be converted- Since:
- 4.1.0
-