Class DefaultMutableConversionService

java.lang.Object
io.micronaut.core.convert.DefaultMutableConversionService
All Implemented Interfaces:
ConversionService, MutableConversionService

public class DefaultMutableConversionService extends Object implements MutableConversionService
The default conversion service. Handles basic type conversion operations.
Since:
1.0
Author:
Graeme Rocher
  • 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 empty Optional is returned.
      Specified by:
      convert in interface ConversionService
      Type Parameters:
      S - The source type
      T - The target type
      Parameters:
      object - The object to convert
      sourceType - The source type
      targetType - The target type
      context - The conversion context
      Returns:
      The optional
    • canConvert

      public <S, T> boolean canConvert(Class<S> sourceType, 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 interface ConversionService
      Type Parameters:
      S - The generic source type
      T - The target source type
      Parameters:
      sourceType - The source type
      targetType - 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 interface MutableConversionService
      Type Parameters:
      S - The source generic type
      T - The target generic type
      Parameters:
      sourceType - The source type
      targetType - The target type
      typeConverter - 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 type
      T - The target type
      Parameters:
      sourceType - The source type
      targetType - The target type
      typeConverter - The converter
    • addConverter

      public <S, T> void addConverter(Class<S> sourceType, Class<T> targetType, Function<S,T> function)
      Description copied from interface: MutableConversionService
      Adds a type converter.
      Specified by:
      addConverter in interface MutableConversionService
      Type Parameters:
      S - The source generic type
      T - The target generic type
      Parameters:
      sourceType - The source type
      targetType - The target type
      function - 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 type
      T - The target type
      Parameters:
      sourceType - The source type
      targetType - The target type
      function - The converter function
    • registerInternalTypeConverters

      @Internal public void registerInternalTypeConverters(Collection<TypeConverterRegistrar> registrars)
      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 - sourceType
      targetType - targetType
      formattingAnnotation - formattingAnnotation
      Returns:
      type converter