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.
  • Field Summary

    Fields inherited from interface org.apache.camel.Ordered

    HIGHEST, LOWEST

    Fields inherited from interface org.apache.camel.TypeConverter

    MISS_VALUE
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    Whether the type converter allows returning null as a valid response.
    <T> T
    convertTo(Class<?> from, Class<T> to, Exchange exchange, Object value)
    Converts the value to the specified type in the context of an exchange
    default <T> T
    convertTo(Class<T> type, Object value)
    Converts the value to the specified type
    default <T> T
    convertTo(Class<T> type, Exchange exchange, Object value)
    Converts the value to the specified type in the context of an exchange
    default int
    Gets the order.
    lookup(Class<?> toType, Class<?> fromType)
    Performs a lookup for a given type converter.
    default <T> T
    mandatoryConvertTo(Class<?> from, Class<T> to, Exchange exchange, Object value)
    Converts the value to the specified type in the context of an exchange
    default <T> T
    mandatoryConvertTo(Class<T> type, Object value)
    Converts the value to the specified type
    default <T> T
    mandatoryConvertTo(Class<T> type, Exchange exchange, Object value)
    Converts the value to the specified type in the context of an exchange
    int
    Number of type converters included
    default <T> T
    tryConvertTo(Class<?> from, Class<T> to, Exchange exchange, Object value)
    Tries to convert the value to the specified type, returning null if not possible to convert.
    default <T> T
    tryConvertTo(Class<T> type, Object value)
    Tries to convert the value to the specified type, returning null if not possible to convert.
    default <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.
  • Method Details

    • 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
    • mandatoryConvertTo

      default <T> T mandatoryConvertTo(Class<?> from, Class<T> to, Exchange exchange, Object value) throws TypeConversionException, NoTypeConversionAvailableException
      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, is never null
      Throws:
      TypeConversionException - is thrown if error during type conversion
      NoTypeConversionAvailableException - if no type converters exists to convert to the given type
    • 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
    • mandatoryConvertTo

      default <T> T mandatoryConvertTo(Class<T> type, Object value) throws TypeConversionException, NoTypeConversionAvailableException
      Description copied from interface: TypeConverter
      Converts the value to the specified type
      Specified by:
      mandatoryConvertTo in interface TypeConverter
      Parameters:
      type - the requested type
      value - the value to be converted
      Returns:
      the converted value, is never null
      Throws:
      TypeConversionException - is thrown if error during type conversion
      NoTypeConversionAvailableException - if no type converters exists to convert to the given type
    • mandatoryConvertTo

      default <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException, NoTypeConversionAvailableException
      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:
      mandatoryConvertTo in interface TypeConverter
      Parameters:
      type - the requested type
      exchange - the current exchange
      value - the value to be converted
      Returns:
      the converted value, is never null
      Throws:
      TypeConversionException - is thrown if error during type conversion
      NoTypeConversionAvailableException - if no type converters exists to convert to the given type
    • 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