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
Fields Modifier and Type Field Description static Object
MISS_VALUE
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
allowNull()
Whether the type converter allows returning null as a valid response.<T> T
convertTo(Class<T> type, Object value)
Converts the value to the specified type<T> T
convertTo(Class<T> type, Exchange exchange, Object value)
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 Detail
-
MISS_VALUE
static final Object MISS_VALUE
-
-
Method Detail
-
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
<T> T convertTo(Class<T> type, Object value) throws TypeConversionException
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
<T> T convertTo(Class<T> type, 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:
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
<T> T tryConvertTo(Class<T> type, Object value)
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
<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. 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
-
-