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
FieldsModifier and TypeFieldDescriptionstatic final ConversionServiceThe 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.default <T> Optional<T>convert(Object object, Class<T> targetType, ConversionContext context) Attempts to convert the given object to the given target type.default <S,T> Optional<T> Attempts to convert the given object to the given target type from the given source type.default <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.default <T> TconvertRequired(@Nullable Object value, Argument<T> argument) Convert the value to the given type.default <T> TconvertRequired(@Nullable Object value, Class<T> type) Convert the value to the given type.default <T> TconvertRequired(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 emptyOptionalis returned.- Type Parameters:
T- The target type- Parameters:
object- The object to converttargetType- The target typecontext- The conversion context- Returns:
- The optional
-
convert
default <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. If conversion fails or is not possible an emptyOptionalis returned.- 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
- Since:
- 4.2.0
-
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 emptyOptionalis 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 emptyOptionalis 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 from the given source type. If conversion fails or is not possible an emptyOptionalis returned.- Type Parameters:
S- The source typeT- The target type- Parameters:
object- The object to convertsourceType- The source typetargetType- The target type- Returns:
- The optional
- Since:
- 4.2.0
-
convert
Attempts to convert the given object to the given target type. If conversion fails or is not possible an emptyOptionalis 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
-