in invoker/core/src/main/java/com/google/cloud/functions/invoker/Event.java [45:94]
public Event deserialize(
JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext)
throws JsonParseException {
JsonObject root = jsonElement.getAsJsonObject();
JsonElement data = root.get("data");
CloudFunctionsContext context;
if (root.has("context")) {
JsonObject contextCopy = root.getAsJsonObject("context").deepCopy();
context =
jsonDeserializationContext.deserialize(
adjustContextResource(contextCopy), CloudFunctionsContext.class);
} else if (isPubSubEmulatorPayload(root)) {
JsonObject message = root.getAsJsonObject("message");
String timestampString =
message.has("publishTime")
? message.get("publishTime").getAsString()
: DateTimeFormatter.ISO_INSTANT.format(OffsetDateTime.now());
context =
CloudFunctionsContext.builder()
.setEventType("google.pubsub.topic.publish")
.setTimestamp(timestampString)
.setEventId(message.get("messageId").getAsString())
.setResource(
"{"
+ "\"name\":null,"
+ "\"service\":\"pubsub.googleapis.com\","
+ "\"type\":\"type.googleapis.com/google.pubsub.v1.PubsubMessage\""
+ "}")
.build();
JsonObject marshalledData = new JsonObject();
marshalledData.addProperty("@type", "type.googleapis.com/google.pubsub.v1.PubsubMessage");
marshalledData.add("data", message.get("data"));
if (message.has("attributes")) {
marshalledData.add("attributes", message.get("attributes"));
}
data = marshalledData;
} else {
JsonObject rootCopy = root.deepCopy();
rootCopy.remove("data");
context =
jsonDeserializationContext.deserialize(
adjustContextResource(rootCopy), CloudFunctionsContext.class);
}
return Event.of(data, context);
}