@@ -900,7 +900,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
|||||||
if (ObjectUtils.isArray(payload)) {
|
if (ObjectUtils.isArray(payload)) {
|
||||||
payload = CollectionUtils.arrayToList(payload);
|
payload = CollectionUtils.arrayToList(payload);
|
||||||
}
|
}
|
||||||
if (payload instanceof Collection
|
if (payload instanceof Collection && !CollectionUtils.isEmpty((Collection<?>) payload)
|
||||||
&& Message.class.isAssignableFrom(CollectionUtils.findCommonElementType((Collection<?>) payload))) {
|
&& Message.class.isAssignableFrom(CollectionUtils.findCommonElementType((Collection<?>) payload))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2020 the original author or authors.
|
* Copyright 2019-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,7 @@ import java.io.Serializable;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -47,6 +48,7 @@ import org.springframework.cloud.function.context.FunctionRegistration;
|
|||||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||||
import org.springframework.cloud.function.context.FunctionType;
|
import org.springframework.cloud.function.context.FunctionType;
|
||||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||||
|
import org.springframework.cloud.function.json.JsonMapper;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -73,12 +75,14 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||||||
*/
|
*/
|
||||||
public class BeanFactoryAwareFunctionRegistryTests {
|
public class BeanFactoryAwareFunctionRegistryTests {
|
||||||
|
|
||||||
|
private ApplicationContext context;
|
||||||
|
|
||||||
private FunctionCatalog configureCatalog() {
|
private FunctionCatalog configureCatalog() {
|
||||||
return this.configureCatalog(SampleFunctionConfiguration.class);
|
return this.configureCatalog(SampleFunctionConfiguration.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FunctionCatalog configureCatalog(Class<?>... configClass) {
|
private FunctionCatalog configureCatalog(Class<?>... configClass) {
|
||||||
ApplicationContext context = new SpringApplicationBuilder(configClass)
|
this.context = new SpringApplicationBuilder(configClass)
|
||||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||||
"--spring.main.lazy-initialization=true");
|
"--spring.main.lazy-initialization=true");
|
||||||
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||||
@@ -550,6 +554,28 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
assertThat(result.block()).isEqualTo("hello");
|
assertThat(result.block()).isEqualTo("hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@Test
|
||||||
|
public void testGH_635() throws Exception {
|
||||||
|
FunctionCatalog catalog = this.configureCatalog(SCF_GH_635ConfigurationAsFunction.class);
|
||||||
|
Function lmFunction = catalog.lookup("emptyMessageList", "application/json");
|
||||||
|
List<Message<?>> emptyListOfMessages = (List<Message<?>>) lmFunction.apply(MessageBuilder.withPayload("hello").build());
|
||||||
|
assertThat(emptyListOfMessages).isEmpty();
|
||||||
|
emptyListOfMessages = (List<Message<?>>) lmFunction.apply("hello");
|
||||||
|
assertThat(emptyListOfMessages).isEmpty();
|
||||||
|
|
||||||
|
JsonMapper mapper = this.context.getBean(JsonMapper.class);
|
||||||
|
Function lsFunction = catalog.lookup("emptyStringList", "application/json");
|
||||||
|
Message<byte[]> emptyListOfString = (Message<byte[]>) lsFunction.apply(MessageBuilder.withPayload("hello").build());
|
||||||
|
List resultList = mapper.fromJson(emptyListOfString.getPayload(), List.class);
|
||||||
|
assertThat(resultList).isEmpty();
|
||||||
|
emptyListOfString = (Message<byte[]>) lsFunction.apply("hello");
|
||||||
|
resultList = mapper.fromJson(emptyListOfString.getPayload(), List.class);
|
||||||
|
assertThat(resultList).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
public static class PojoToMessageFunctionCompositionConfiguration {
|
public static class PojoToMessageFunctionCompositionConfiguration {
|
||||||
|
|
||||||
@@ -967,6 +993,20 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
public static class SCF_GH_635ConfigurationAsFunction {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Function<String, List<Message<?>>> emptyMessageList() {
|
||||||
|
return input -> Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Function<String, List<String>> emptyStringList() {
|
||||||
|
return input -> Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Person {
|
public static class Person {
|
||||||
private String name;
|
private String name;
|
||||||
private int id;
|
private int id;
|
||||||
|
|||||||
Reference in New Issue
Block a user