@@ -1325,16 +1325,6 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
return type;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private boolean isConversionHintRequired(Type actualType, Class<?> rawType) {
|
||||
if (Collection.class.isAssignableFrom(rawType) || Map.class.isAssignableFrom(rawType)) {
|
||||
return true;
|
||||
}
|
||||
return rawType != actualType && !FunctionTypeUtils.isMessage(actualType);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -1362,7 +1352,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
Class<?> rawType = FunctionTypeUtils.isMessage(type)
|
||||
? FunctionTypeUtils.getRawType(itemType)
|
||||
: FunctionTypeUtils.getRawType(type);
|
||||
convertedInput = this.isConversionHintRequired(type, rawType)
|
||||
convertedInput = type instanceof ParameterizedType
|
||||
? SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType, itemType)
|
||||
: SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType);
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.assertj.core.util.Arrays;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -36,6 +38,7 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -66,6 +69,26 @@ public class UserIssuesTests {
|
||||
assertThat(result).isEqualTo(3);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testIssue1075() throws Exception {
|
||||
FunctionCatalog catalog = this.configureCatalog(Issue1075StreamConfiguration.class);
|
||||
|
||||
|
||||
List<Object> list = Arrays.asList(new Product[] {new Product("foo"), new Product("bar")});
|
||||
Event event = new Event(list);
|
||||
EventHolder eventHolder = new EventHolder(event);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String message = mapper.writeValueAsString(eventHolder);
|
||||
Function function = catalog.lookup("somethingYouShouldNeverDo");
|
||||
boolean result = (boolean) function.apply(
|
||||
new GenericMessage<String>(message));
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testIssue602asPOJO() throws Exception {
|
||||
FunctionCatalog catalog = this.configureCatalog(Issue602Configuration.class);
|
||||
@@ -128,6 +151,59 @@ public class UserIssuesTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
public static class Issue1075StreamConfiguration {
|
||||
@Bean
|
||||
public Function<Message<EventHolder<Event<List<Product>>>>, Boolean> somethingYouShouldNeverDo() {
|
||||
return message -> {
|
||||
List<Product> products = message.getPayload().getPayload().getPayload();
|
||||
assertThat(products.get(0).getName()).isEqualTo("foo");
|
||||
assertThat(products.get(1).getName()).isEqualTo("bar");
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class EventHolder<T> {
|
||||
private T payload;
|
||||
|
||||
public EventHolder() {
|
||||
}
|
||||
|
||||
public EventHolder(T payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public T getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(T payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Event<T> {
|
||||
private T payload;
|
||||
|
||||
public Event() {
|
||||
}
|
||||
|
||||
public Event(T payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public T getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(T payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
public static class Issue601Configuration {
|
||||
@@ -148,6 +224,13 @@ public class UserIssuesTests {
|
||||
public static class Product {
|
||||
private String name;
|
||||
|
||||
public Product() {
|
||||
}
|
||||
|
||||
public Product(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user