Interface TypeConverter<S,​T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.util.Optional<T> convert​(S object, java.lang.Class<T> targetType)
      Converts from the given source object type to the target type.
      java.util.Optional<T> convert​(S object, java.lang.Class<T> targetType, ConversionContext context)
      Converts from the given source object type to the target type.
      static <ST,​TT>
      TypeConverter<ST,​TT>
      of​(java.lang.Class<ST> sourceType, java.lang.Class<TT> targetType, java.util.function.Function<ST,​TT> converter)
      Creates a new TypeConverter for the give source type, target type and conversion function.
    • Method Detail

      • convert

        default java.util.Optional<T> convert​(S object,
                                              java.lang.Class<T> targetType)
        Converts from the given source object type to the target type.
        Parameters:
        object - The object type
        targetType - The target type being converted to
        Returns:
        The converted type or empty if the conversion is not possible
      • convert

        java.util.Optional<T> convert​(S object,
                                      java.lang.Class<T> targetType,
                                      ConversionContext context)
        Converts from the given source object type to the target type. Implementers should take care to return Optional.empty() in case the object is not convertible by catching any necessary exceptions and failing gracefully.
        Parameters:
        object - The object type
        targetType - The target type being converted to
        context - The ConversionContext
        Returns:
        The converted type or empty if the conversion is not possible
      • of

        static <ST,​TT> TypeConverter<ST,​TT> of​(java.lang.Class<ST> sourceType,
                                                           java.lang.Class<TT> targetType,
                                                           java.util.function.Function<ST,​TT> converter)
        Creates a new TypeConverter for the give source type, target type and conversion function.
        Type Parameters:
        ST - The source generic type
        TT - The target generic type
        Parameters:
        sourceType - The source type
        targetType - The target type
        converter - The converter function
        Returns:
        The converter instance