Package org.apache.camel.spi
Interface BulkTypeConverters
- All Superinterfaces:
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.TypeConverter
MISS_VALUE -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanWhether the type converter allows returning null as a valid response.<T> TConverts the value to the specified type in the context of an exchangedefault <T> TConverts the value to the specified typedefault <T> TConverts the value to the specified type in the context of an exchangedefault intgetOrder()Gets the order.Performs a lookup for a given type converter.default <T> TmandatoryConvertTo(Class<?> from, Class<T> to, Exchange exchange, Object value) Converts the value to the specified type in the context of an exchangedefault <T> TmandatoryConvertTo(Class<T> type, Object value) Converts the value to the specified typedefault <T> TmandatoryConvertTo(Class<T> type, Exchange exchange, Object value) Converts the value to the specified type in the context of an exchangeintsize()Number of type converters includeddefault <T> TtryConvertTo(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> TtryConvertTo(Class<T> type, Object value) Tries to convert the value to the specified type, returning null if not possible to convert.default <T> TtryConvertTo(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
Performs a lookup for a given type converter.- Parameters:
toType- the type to convert tofromType- 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 typeto- the to typeexchange- the current exchangevalue- 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 typeto- the to typevalue- 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 typeto- the to typeexchange- the current exchangevalue- the value to be converted- Returns:
- the converted value, is never null
- Throws:
TypeConversionException- is thrown if error during type conversionNoTypeConversionAvailableException- 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:OrderedGets 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 useInteger.MAX_VALUEor egOrdered.LOWEST. -
allowNull
default boolean allowNull()Description copied from interface:TypeConverterWhether 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:
allowNullin interfaceTypeConverter
-
convertTo
Description copied from interface:TypeConverterConverts the value to the specified type- Specified by:
convertToin interfaceTypeConverter- Parameters:
type- the requested typevalue- 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:TypeConverterConverts 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:
convertToin interfaceTypeConverter- Parameters:
type- the requested typeexchange- the current exchangevalue- 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:TypeConverterConverts the value to the specified type- Specified by:
mandatoryConvertToin interfaceTypeConverter- Parameters:
type- the requested typevalue- the value to be converted- Returns:
- the converted value, is never null
- Throws:
TypeConversionException- is thrown if error during type conversionNoTypeConversionAvailableException- 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:TypeConverterConverts 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:
mandatoryConvertToin interfaceTypeConverter- Parameters:
type- the requested typeexchange- the current exchangevalue- the value to be converted- Returns:
- the converted value, is never null
- Throws:
TypeConversionException- is thrown if error during type conversionNoTypeConversionAvailableException- if no type converters exists to convert to the given type
-
tryConvertTo
Description copied from interface:TypeConverterTries 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:
tryConvertToin interfaceTypeConverter- Parameters:
type- the requested typevalue- the value to be converted- Returns:
- the converted value, or null if not possible to convert
-
tryConvertTo
Description copied from interface:TypeConverterTries 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:
tryConvertToin interfaceTypeConverter- Parameters:
type- the requested typeexchange- the current exchangevalue- the value to be converted- Returns:
- the converted value, or null if not possible to convert
-