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 c6bc4f553f
commit 536d3d6e80
2 changed files with 15 additions and 2 deletions

View File

@@ -1060,7 +1060,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
} }
} }
else { 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()) { if (convertedInput != null && logger.isDebugEnabled()) {
logger.debug("Converted input: " + input + " to: " + convertedInput); logger.debug("Converted input: " + input + " to: " + convertedInput);
} }

View File

@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -530,6 +531,18 @@ public class BeanFactoryAwareFunctionRegistryTests {
registry.register(e); 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" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testValueWrappedInMessageIfNecessary() { public void testValueWrappedInMessageIfNecessary() {
@@ -934,7 +947,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
@Bean @Bean
public Function<Map<String, Object>, Person> maptopojo() { public Function<Map<String, Object>, Person> maptopojo() {
return map -> { return map -> {
Person person = new Person((String) map.get("name"), Integer.parseInt((String) map.get("id"))); Person person = (Person) map.get("person");
return person; return person;
}; };
} }