return Void.TYPE;
}
}
// try to find a suitable type converter
TypeConverter converter = getOrFindTypeConverter(type, value);
if (converter != null) {
log.trace("Using converter: {} to convert {}", converter, key);
Object rc;
if (tryConvert) {
rc = converter.tryConvertTo(type, exchange, value);
} else {
rc = converter.convertTo(type, exchange, value);
}
if (rc != null) {
return rc;
}
}
// not found with that type then if it was a primitive type then try again with the wrapper type
if (type.isPrimitive()) {
Class<?> primitiveType = ObjectHelper.convertPrimitiveTypeToWrapperType(type);
if (primitiveType != type) {
Class<?> fromType = value.getClass();
TypeConverter tc = getOrFindTypeConverter(primitiveType, value);
if (tc != null) {
// add the type as a known type converter as we can convert from primitive to object converter
addTypeConverter(type, fromType, tc);
Object rc;
if (tryConvert) {
rc = tc.tryConvertTo(primitiveType, exchange, value);
} else {
rc = tc.convertTo(primitiveType, exchange, value);
}
if (rc != null) {
return rc;
}
}
}
}
// fallback converters
for (FallbackTypeConverter fallback : fallbackConverters) {
TypeConverter tc = fallback.getFallbackTypeConverter();
Object rc;
if (tryConvert) {
rc = tc.tryConvertTo(type, exchange, value);
} else {
rc = tc.convertTo(type, exchange, value);
}
if (Void.TYPE.equals(rc)) {
// it cannot be converted so give up
return Void.TYPE;