GH-395 Add support for non-message json to be converted as POJO
Resolves #395
This commit is contained in:
@@ -69,6 +69,7 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.converter.CompositeMessageConverter;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -668,7 +669,14 @@ public class BeanFactoryAwareFunctionRegistry
|
||||
}
|
||||
}
|
||||
else if (rawType instanceof Class<?>) { // see AWS adapter with WildardTypeImpl and Azure with Voids
|
||||
convertedValue = conversionService.convert(value, (Class<?>) rawType);
|
||||
try {
|
||||
convertedValue = conversionService.convert(value, (Class<?>) rawType);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (value instanceof String || value instanceof byte[]) {
|
||||
convertedValue = messageConverter.fromMessage(new GenericMessage<Object>(value), (Class<?>) rawType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -282,6 +282,16 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat((Object) catalog.lookup("")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoFunctionAsJson() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
Function<String, Person> uppercasePerson = catalog.lookup("uppercasePerson");
|
||||
|
||||
Person person = uppercasePerson.apply("{\"name\":\"bill\",\"id\":2}");
|
||||
assertThat(person.getName()).isEqualTo("BILL");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user