GH-794 Address regression with input type conversion of Maps

Resolves #794
This commit is contained in:
Oleg Zhurakousky
2022-01-26 12:48:51 +01:00
parent 5d26534283
commit da4819640f
2 changed files with 15 additions and 2 deletions

View File

@@ -1067,7 +1067,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
}
}
else {
convertedInput = this.convertNonMessageInputIfNecessary(type, input, JsonMapper.isJsonString(input) || input instanceof Map);
convertedInput = this.convertNonMessageInputIfNecessary(type, input, JsonMapper.isJsonString(input));
if (convertedInput != null && logger.isDebugEnabled()) {
logger.debug("Converted input: " + input + " to: " + convertedInput);
}

View File

@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -526,6 +527,18 @@ public class BeanFactoryAwareFunctionRegistryTests {
registry.register(e);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testNoConversionOnInputMapIfInputIsMap() {
FunctionCatalog catalog = this.configureCatalog();
Function f = catalog.lookup("maptopojo");
Person p = new Person("John", 123);
Map<String, Object> map = new HashMap<>();
map.put("person", p);
map.put("foo", "foo");
assertThat(f.apply(map)).isInstanceOf(Person.class);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testValueWrappedInMessageIfNecessary() {
@@ -930,7 +943,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
@Bean
public Function<Map<String, Object>, Person> maptopojo() {
return map -> {
Person person = new Person((String) map.get("name"), Integer.parseInt((String) map.get("id")));
Person person = (Person) map.get("person");
return person;
};
}