Remove hard dependency on Gson from FCF adapter in favor of SCF proivided configurable JsonMapper
This commit is contained in:
@@ -26,7 +26,6 @@ import com.google.cloud.functions.HttpFunction;
|
|||||||
import com.google.cloud.functions.HttpRequest;
|
import com.google.cloud.functions.HttpRequest;
|
||||||
import com.google.cloud.functions.HttpResponse;
|
import com.google.cloud.functions.HttpResponse;
|
||||||
import com.google.cloud.functions.RawBackgroundFunction;
|
import com.google.cloud.functions.RawBackgroundFunction;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -53,8 +52,6 @@ public class FunctionInvoker extends AbstractSpringFunctionAdapterInitializer<Ht
|
|||||||
|
|
||||||
private String functionName = "";
|
private String functionName = "";
|
||||||
|
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
|
||||||
public FunctionInvoker() {
|
public FunctionInvoker() {
|
||||||
super();
|
super();
|
||||||
init();
|
init();
|
||||||
@@ -124,7 +121,7 @@ public class FunctionInvoker extends AbstractSpringFunctionAdapterInitializer<Ht
|
|||||||
// If the input type is not PubSubMessage, use the PubSubMessage.data field as
|
// If the input type is not PubSubMessage, use the PubSubMessage.data field as
|
||||||
// payload, and put the full PubSubMessage and Context into message headers.
|
// payload, and put the full PubSubMessage and Context into message headers.
|
||||||
|
|
||||||
PubSubMessage pubSubMessage = gson.fromJson(json, PubSubMessage.class);
|
PubSubMessage pubSubMessage = this.jsonMapper.fromJson(json, PubSubMessage.class);
|
||||||
|
|
||||||
message = getInputType() == Void.class ? null : MessageBuilder.withPayload(pubSubMessage.getData())
|
message = getInputType() == Void.class ? null : MessageBuilder.withPayload(pubSubMessage.getData())
|
||||||
.setHeader("gcf_context", context).setHeader("gcf_message", pubSubMessage).build();
|
.setHeader("gcf_context", context).setHeader("gcf_message", pubSubMessage).build();
|
||||||
@@ -139,7 +136,6 @@ public class FunctionInvoker extends AbstractSpringFunctionAdapterInitializer<Ht
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
log.info("Dropping background function result: " + new String(result.getPayload()));
|
log.info("Dropping background function result: " + new String(result.getPayload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.springframework.boot.WebApplicationType;
|
|||||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||||
import org.springframework.cloud.function.context.config.FunctionContextUtils;
|
import org.springframework.cloud.function.context.config.FunctionContextUtils;
|
||||||
import org.springframework.cloud.function.context.config.RoutingFunction;
|
import org.springframework.cloud.function.context.config.RoutingFunction;
|
||||||
|
import org.springframework.cloud.function.json.JsonMapper;
|
||||||
import org.springframework.cloud.function.utils.FunctionClassUtils;
|
import org.springframework.cloud.function.utils.FunctionClassUtils;
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
import org.springframework.context.ApplicationContextInitializer;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
@@ -80,6 +81,9 @@ public abstract class AbstractSpringFunctionAdapterInitializer<C> implements Clo
|
|||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
protected FunctionCatalog catalog;
|
protected FunctionCatalog catalog;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
protected JsonMapper jsonMapper;
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
public ConfigurableApplicationContext getContext() {
|
public ConfigurableApplicationContext getContext() {
|
||||||
|
|||||||
Reference in New Issue
Block a user