Make ObjectMapper optional
Plain text will just be passed straight through. Fixes gh-226
This commit is contained in:
@@ -32,6 +32,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||||
import org.springframework.cloud.function.context.message.MessageUtils;
|
import org.springframework.cloud.function.context.message.MessageUtils;
|
||||||
import org.springframework.cloud.function.core.FluxWrapper;
|
import org.springframework.cloud.function.core.FluxWrapper;
|
||||||
@@ -64,9 +65,9 @@ public class RequestProcessor {
|
|||||||
|
|
||||||
private final JsonMapper mapper;
|
private final JsonMapper mapper;
|
||||||
|
|
||||||
public RequestProcessor(FunctionInspector inspector, JsonMapper mapper,
|
public RequestProcessor(FunctionInspector inspector, ObjectProvider<JsonMapper> mapper,
|
||||||
StringConverter converter) {
|
StringConverter converter) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper.getIfAvailable();
|
||||||
this.inspector = inspector;
|
this.inspector = inspector;
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
}
|
}
|
||||||
@@ -100,8 +101,8 @@ public class RequestProcessor {
|
|||||||
Class<?> inputType = inspector.getInputType(function);
|
Class<?> inputType = inspector.getInputType(function);
|
||||||
Type itemType = getItemType(function);
|
Type itemType = getItemType(function);
|
||||||
|
|
||||||
Object input = null;
|
Object input = body;
|
||||||
if (StringUtils.hasText(body)) {
|
if (StringUtils.hasText(body) && this.mapper!=null) {
|
||||||
if (body.startsWith("[")) {
|
if (body.startsWith("[")) {
|
||||||
Class<?> collectionType = Collection.class.isAssignableFrom(inputType) ? inputType : Collection.class;
|
Class<?> collectionType = Collection.class.isAssignableFrom(inputType) ? inputType : Collection.class;
|
||||||
input = mapper.toObject(body, ResolvableType
|
input = mapper.toObject(body, ResolvableType
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class FunctionEndpointInitializer
|
|||||||
context.getBeanFactory()));
|
context.getBeanFactory()));
|
||||||
context.registerBean(RequestProcessor.class,
|
context.registerBean(RequestProcessor.class,
|
||||||
() -> new RequestProcessor(context.getBean(FunctionInspector.class),
|
() -> new RequestProcessor(context.getBean(FunctionInspector.class),
|
||||||
context.getBean(JsonMapper.class),
|
context.getBeanProvider(JsonMapper.class),
|
||||||
context.getBean(StringConverter.class)));
|
context.getBean(StringConverter.class)));
|
||||||
context.registerBean(FunctionEndpointFactory.class,
|
context.registerBean(FunctionEndpointFactory.class,
|
||||||
() -> new FunctionEndpointFactory(context.getBean(FunctionCatalog.class),
|
() -> new FunctionEndpointFactory(context.getBean(FunctionCatalog.class),
|
||||||
|
|||||||
Reference in New Issue
Block a user