private String serialize()

in invoker/conformance/src/main/java/com/google/cloud/functions/conformance/BackgroundEventConformanceFunction.java [37:56]


  private String serialize(String data, Context context) {
    JsonObject contextJson = new JsonObject();
    contextJson.addProperty("eventId", context.eventId());
    contextJson.addProperty("timestamp", context.timestamp());
    contextJson.addProperty("eventType", context.eventType());

    if (context.resource().startsWith("{")) {
      JsonElement resource = gson.fromJson(context.resource(), JsonElement.class);
      contextJson.add("resource", resource);
    } else {
      contextJson.addProperty("resource", context.resource());
    }

    JsonObject dataJson = gson.fromJson(data, JsonObject.class);

    JsonObject json = new JsonObject();
    json.add("data", dataJson);
    json.add("context", contextJson);
    return gson.toJson(json);
  }