Interface TypeConverter


  • public interface TypeConverter
    A pluggable strategy to be able to convert objects to different types such as to and from String, InputStream/OutputStream, Reader/Writer, Document, byte[], ByteBuffer etc
    • Field Detail

      • MISS_VALUE

        static final Object MISS_VALUE
    • Method Detail

      • allowNull

        boolean allowNull()
        Whether the type converter allows returning null as a valid response.

        By default null is not a valid response, returning false from this method.

      • convertTo

        <T> T convertTo​(Class<T> type,
                        Object value)
                 throws TypeConversionException
        Converts the value to the specified type
        Parameters:
        type - the requested type
        value - the value to be converted
        Returns:
        the converted value, or null if not possible to convert
        Throws:
        TypeConversionException - is thrown if error during type conversion
      • convertTo

        <T> T convertTo​(Class<T> type,
                        Exchange exchange,
                        Object value)
                 throws TypeConversionException
        Converts the value to the specified type in the context of an exchange

        Used when conversion requires extra information from the current exchange (such as encoding).

        Parameters:
        type - the requested type
        exchange - the current exchange
        value - the value to be converted
        Returns:
        the converted value, or null if not possible to convert
        Throws:
        TypeConversionException - is thrown if error during type conversion
      • tryConvertTo

        <T> T tryConvertTo​(Class<T> type,
                           Object value)
        Tries to convert the value to the specified type, returning null if not possible to convert.

        This method will not throw an exception if an exception occurred during conversion.

        Parameters:
        type - the requested type
        value - the value to be converted
        Returns:
        the converted value, or null if not possible to convert
      • tryConvertTo

        <T> T tryConvertTo​(Class<T> type,
                           Exchange exchange,
                           Object value)
        Tries to convert the value to the specified type in the context of an exchange, returning null if not possible to convert.

        This method will not throw an exception if an exception occurred during conversion. Converts the value to the specified type in the context of an exchange

        Used when conversion requires extra information from the current exchange (such as encoding).

        Parameters:
        type - the requested type
        exchange - the current exchange
        value - the value to be converted
        Returns:
        the converted value, or null if not possible to convert