Adding support for extracting payload only for cases where conversion is not necessary

This commit is contained in:
Oleg Zhurakousky
2019-07-24 13:57:17 +02:00
parent c4f1f4505c
commit 694c7fa1bb

View File

@@ -516,25 +516,31 @@ public class BeanFactoryAwareFunctionRegistry
else { else {
// this needs revisiting as the type is not always Class (think really complex types) // this needs revisiting as the type is not always Class (think really complex types)
Type rawType = FunctionTypeUtils.unwrapActualTypeByIndex(type, 0); Type rawType = FunctionTypeUtils.unwrapActualTypeByIndex(type, 0);
if (!(rawType instanceof Class<?>) && rawType instanceof ParameterizedType) { if (/*!(rawType instanceof Class<?>) && */rawType instanceof ParameterizedType) {
rawType = ((ParameterizedType) rawType).getRawType(); rawType = ((ParameterizedType) rawType).getRawType();
} }
if (value instanceof Message<?>) { // see AWS adapter with Optional payload if (value instanceof Message<?>) { // see AWS adapter with Optional payload
if (!(((Message<?>) value).getPayload() instanceof Optional)) { if (messageNeedsConversion(rawType, (Message<?>) value)) {
convertedValue = messageConverter.fromMessage((Message<?>) value, (Class<?>) rawType, type); convertedValue = messageConverter.fromMessage((Message<?>) value, (Class<?>) rawType, type);
if (FunctionTypeUtils.isMessage(type)) { if (FunctionTypeUtils.isMessage(type)) {
convertedValue = MessageBuilder.withPayload(convertedValue).copyHeaders(((Message<?>) value).getHeaders()).build(); convertedValue = MessageBuilder.withPayload(convertedValue).copyHeaders(((Message<?>) value).getHeaders()).build();
} }
} }
} else if (!FunctionTypeUtils.isMessage(type)) {
else { convertedValue = ((Message<?>) convertedValue).getPayload();
if (rawType instanceof Class<?>) { // see AWS adapter with WildardTypeImpl and Azure with Voids
convertedValue = conversionService.convert(value, (Class<?>) rawType);
} }
} }
else if (rawType instanceof Class<?>) { // see AWS adapter with WildardTypeImpl and Azure with Voids
convertedValue = conversionService.convert(value, (Class<?>) rawType);
}
} }
return convertedValue; return convertedValue;
} }
private boolean messageNeedsConversion(Type rawType, Message<?> message) {
return rawType instanceof Class<?>
&& !(message.getPayload() instanceof Optional)
&& !(message.getPayload().getClass().isAssignableFrom(((Class<?>) rawType)));
}
} }
} }