Package org.apache.camel
Interface TypeConverter
- All Known Subinterfaces:
BulkTypeConverters
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether the type converter allows returning null as a valid response.<T> T
Converts the value to the specified type<T> T
Converts the value to the specified type in the context of an exchange<T> T
mandatoryConvertTo
(Class<T> type, Object value) Converts the value to the specified type<T> T
mandatoryConvertTo
(Class<T> type, Exchange exchange, Object value) Converts the value to the specified type in the context of an exchange<T> T
tryConvertTo
(Class<T> type, Object value) Tries to convert the value to the specified type, returning null if not possible to convert.<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.
-
Field Details
-
MISS_VALUE
-
-
Method Details
-
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
Converts the value to the specified type- 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
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 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
<T> T mandatoryConvertTo(Class<T> type, Object value) throws TypeConversionException, NoTypeConversionAvailableException Converts the value to the specified type- 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
<T> T mandatoryConvertTo(Class<T> type, 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:
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
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 typevalue
- the value to be converted- Returns:
- the converted value, or null if not possible to convert
-
tryConvertTo
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 typeexchange
- the current exchangevalue
- the value to be converted- Returns:
- the converted value, or null if not possible to convert
-