Interface BulkTypeConverters

All Superinterfaces:
Ordered, TypeConverter

public interface BulkTypeConverters extends Ordered, TypeConverter
A source-code-generated, compile-time-optimized bundle of TypeConverter instances for use with the type conversion infrastructure.

During the Camel build phase, all classes annotated with Converter in a module are collected and merged into a single generated class implementing this interface. At runtime the TypeConverterRegistry registers each such bulk class once via TypeConverterRegistry.addBulkTypeConverters(BulkTypeConverters), replacing the overhead of per-pair hash map lookups with a single polymorphic dispatch through the generated convertTo(Class, Class, org.apache.camel.Exchange, Object) method, significantly reducing overhead for high-throughput routes.

Since:
3.7
See Also:
  • Field Summary

    Fields inherited from interface Ordered

    HIGHEST, LOWEST

    Fields inherited from interface TypeConverter

    MISS_VALUE
  • Method Summary

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

      @Nullable 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> @Nullable T convertTo(Class<?> from, Class<T> to, @Nullable Exchange exchange, @Nullable 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> @Nullable T tryConvertTo(Class<?> from, Class<T> to, @Nullable Exchange exchange, @Nullable 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, @Nullable Exchange exchange, @Nullable 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> @Nullable T convertTo(Class<T> type, @Nullable 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> @Nullable T convertTo(Class<T> type, @Nullable Exchange exchange, @Nullable 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, @Nullable 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, @Nullable Exchange exchange, @Nullable 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> @Nullable T tryConvertTo(Class<T> type, @Nullable 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> @Nullable T tryConvertTo(Class<T> type, @Nullable Exchange exchange, @Nullable 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