GH-395 Add support for non-message json to be converted as POJO

Resolves #395
This commit is contained in:
Oleg Zhurakousky
2019-10-01 14:06:17 -04:00
parent 97bea81836
commit 52f1f04020
2 changed files with 19 additions and 1 deletions

View File

@@ -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()) {

View File

@@ -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