Interface BulkTypeConverters

  • All Superinterfaces:
    Ordered, TypeConverter

    public interface BulkTypeConverters
    extends Ordered, TypeConverter
    Bulk type converters that often comes out of the box with Apache Camel. Camel does a build phase where the Camel artifacts are scanned for Converters and then bulked together into a single source code generated class. This class is then used at runtime as an optimized and really fast way of using all those type converters by the TypeConverterRegistry.
    • Method Detail

      • lookup

        TypeConverter lookup​(Class<?> toType,
                             Class<?> fromType)
        Performs a lookup for a given type converter.
        Parameters:
        toType - the type to convert to
        fromType - the type to convert from
        Returns:
        the type converter or null if not found.
      • convertTo

        <T> T convertTo​(Class<?> from,
                        Class<T> to,
                        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:
        from - the from type
        to - the to type
        exchange - the current exchange
        value - the value to be converted
        Returns:
        the converted value, null if no converter can covert this, or Void.class if a converter converted the value to null and was allowed to return null.
        Throws:
        TypeConversionException - is thrown if error during type conversion
      • tryConvertTo

        default <T> T tryConvertTo​(Class<?> from,
                                   Class<T> to,
                                   Exchange exchange,
                                   Object value)
                            throws TypeConversionException
        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:
        from - the from type
        to - the to type
        value - the value to be converted
        Returns:
        the converted value, or null if not possible to convert
        Throws:
        TypeConversionException
      • size

        int size()
        Number of type converters included
      • getOrder

        default int getOrder()
        Description copied from interface: Ordered
        Gets the order.

        Use low numbers for higher priority. Normally the sorting will start from 0 and move upwards. So if you want to be last then use Integer.MAX_VALUE or eg Ordered.LOWEST.

        Specified by:
        getOrder in interface Ordered
        Returns:
        the order
      • allowNull

        default boolean allowNull()
        Description copied from interface: TypeConverter
        Whether the type converter allows returning null as a valid response.

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

        Specified by:
        allowNull in interface TypeConverter
      • convertTo

        default <T> T convertTo​(Class<T> type,
                                Object value)
                         throws TypeConversionException
        Description copied from interface: TypeConverter
        Converts the value to the specified type
        Specified by:
        convertTo in interface TypeConverter
        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

        default <T> T convertTo​(Class<T> type,
                                Exchange exchange,
                                Object value)
                         throws TypeConversionException
        Description copied from interface: TypeConverter
        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).

        Specified by:
        convertTo in interface TypeConverter
        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

        default <T> T tryConvertTo​(Class<T> type,
                                   Object value)
        Description copied from interface: TypeConverter
        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.

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

        default <T> T tryConvertTo​(Class<T> type,
                                   Exchange exchange,
                                   Object value)
        Description copied from interface: TypeConverter
        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).

        Specified by:
        tryConvertTo in interface TypeConverter
        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