GH-1052 Fix collection/array processing for AWS invocations with Publisher input type functions

Resolves #1052
This commit is contained in:
Oleg Zhurakousky
2023-07-13 15:20:22 +02:00
parent 351e73b7f4
commit aff82e1457
7 changed files with 293 additions and 50 deletions

View File

@@ -820,7 +820,12 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
if (!this.isRoutingFunction() && !(input instanceof Publisher)) {
Object payload = input;
if (input instanceof Message) {
payload = ((Message) input).getPayload();
if (((Message) input).getHeaders().containsKey("payload")) {
payload = ((Message) input).getHeaders().get("payload");
}
else {
payload = ((Message) input).getPayload();
}
}
if (JsonMapper.isJsonStringRepresentsCollection(payload)
&& !FunctionTypeUtils.isTypeCollection(this.inputType) && !FunctionTypeUtils.isTypeArray(this.inputType)) {

View File

@@ -39,6 +39,9 @@ public abstract class JsonMapper {
@SuppressWarnings("unchecked")
public <T> T fromJson(Object json, Type type) {
if (json instanceof Collection<?>) {
if (FunctionTypeUtils.isTypeCollection(type)) {
return (T) json;
}
Collection<?> inputs = (Collection<?>) json;
Type itemType = FunctionTypeUtils.getImmediateGenericType(type, 0);
Collection<?> results = FunctionTypeUtils.getRawType(type).isAssignableFrom(List.class)
@@ -112,6 +115,9 @@ public abstract class JsonMapper {
public static boolean isJsonStringRepresentsCollection(Object value) {
boolean isJson = false;
if (value instanceof Iterable && !value.getClass().getPackage().getName().startsWith("reactor.util.function")) {
return true;
}
if (value instanceof byte[]) {
value = new String((byte[]) value, StandardCharsets.UTF_8);
}