GH-640 Fix NPE with non-Message json conversion
Resolves #640 Added test
This commit is contained in:
@@ -1001,10 +1001,10 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
&& SimpleFunctionRegistry.this.conversionService.canConvert(input.getClass(), rawInputType)) {
|
||||
convertedInput = SimpleFunctionRegistry.this.conversionService.convert(input, rawInputType);
|
||||
}
|
||||
if (convertedInput == null && input.getClass().isAssignableFrom(rawInputType)) {
|
||||
convertedInput = input;
|
||||
if (convertedInput == null && logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to convert input '" + input + "' to type " + inputType + ". Will use it as is.");
|
||||
}
|
||||
return convertedInput;
|
||||
return convertedInput == null ? input : convertedInput;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -86,6 +86,21 @@ public class SimpleFunctionRegistryTests {
|
||||
this.conversionService = new DefaultConversionService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSCF640() {
|
||||
Echo function = new Echo();
|
||||
FunctionRegistration<Echo> registration = new FunctionRegistration<>(
|
||||
function, "echo").type(FunctionType.of(Echo.class));
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
|
||||
FunctionInvocationWrapper lookedUpFunction = catalog.lookup("echo");
|
||||
Object result = lookedUpFunction.apply("{\"HELLO\":\"WORLD\"}");
|
||||
assertThat(result).isNotInstanceOf(Message.class);
|
||||
assertThat(result).isEqualTo("{\"HELLO\":\"WORLD\"}");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSCF588() {
|
||||
@@ -468,6 +483,15 @@ public class SimpleFunctionRegistryTests {
|
||||
|
||||
}
|
||||
|
||||
private static class Echo implements Function<Object, Object> {
|
||||
|
||||
@Override
|
||||
public Object apply(Object t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class UpperCaseMessage
|
||||
implements Function<Message<String>, Message<String>> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user