GH-596 Add support for handling conversion of complex types
Resolves #596
This commit is contained in:
@@ -269,6 +269,29 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(block).isNull();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void textTypeConversionWithComplexInputType() {
|
||||
FunctionCatalog catalog = this.configureCatalog(ComplexTypeFunctionConfiguration.class);
|
||||
Function function = catalog.lookup("function");
|
||||
|
||||
// as String
|
||||
String result = (String) function.apply("{\"key\":\"purchase\",\"data\":{\"name\":\"bike\"}}");
|
||||
assertThat(result).isEqualTo("BIKE");
|
||||
|
||||
// as byte[]
|
||||
result = (String) function.apply("{\"key\":\"purchase\",\"data\":{\"name\":\"bike\"}}".getBytes());
|
||||
assertThat(result).isEqualTo("BIKE");
|
||||
|
||||
// as Message<String>
|
||||
result = (String) function.apply(MessageBuilder.withPayload("{\"key\":\"purchase\",\"data\":{\"name\":\"bike\"}}").build());
|
||||
assertThat(result).isEqualTo("BIKE");
|
||||
|
||||
// as Message<BYTE[]>
|
||||
result = (String) function.apply(MessageBuilder.withPayload("{\"key\":\"purchase\",\"data\":{\"name\":\"bike\"}}".getBytes()).build());
|
||||
assertThat(result).isEqualTo("BIKE");
|
||||
}
|
||||
|
||||
// MULTI INPUT/OUTPUT
|
||||
|
||||
|
||||
@@ -919,4 +942,48 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
public static class ComplexTypeFunctionConfiguration {
|
||||
@Bean
|
||||
public Function<Event<String, Product>, String> function() {
|
||||
return v -> v.getData().getName().toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Product {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Event<K, V> {
|
||||
|
||||
private K key;
|
||||
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
private V data;
|
||||
|
||||
public V getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(V data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +127,8 @@ public class SimpleFunctionRegistryTests {
|
||||
assertThat(lookedUpFunction).isNull();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunctionComposition() {
|
||||
FunctionRegistration<UpperCase> upperCaseRegistration = new FunctionRegistration<>(
|
||||
@@ -500,5 +502,4 @@ public class SimpleFunctionRegistryTests {
|
||||
.map(lst -> lst.stream().map(Person::getName).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user