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 <T> Optional<T> convert(Object object, 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 empty Optional is returned.
      Specified by:
      convert in interface ConversionService
      Type Parameters:
      T - The generic type
      Parameters:
      object - The object to convert
      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
    • 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
    • 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