public JsonObject serializeGraph(Graph graph) throws IOException {
    String graphJsonResult;
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
      GraphSONWriter.outputGraph(graph, os, graphsonMode);
      graphJsonResult = os.toString("UTF-8");
    }

    return new JsonObject().putObject("graph", new JsonObject(graphJsonResult));
  }
Beispiel #2
0
 @Override
 public void writeTo(
     Graph data,
     Class<?> type,
     Type genericType,
     Annotation[] annotations,
     MediaType mediaType,
     MultivaluedMap<String, Object> headers,
     OutputStream out)
     throws IOException {
   GraphSONWriter.outputGraph(data, out, GraphSONMode.COMPACT);
   out.flush();
 }
  public static String serializeGraph(Graph graph) throws IOException {
    OutputStream output =
        new OutputStream() {
          private StringBuilder string = new StringBuilder();

          @Override
          public void write(int b) throws IOException {
            this.string.append((char) b);
          }

          public String toString() {
            return this.string.toString();
          }
        };

    GraphSONWriter.outputGraph(graph, output);
    String json = output.toString();

    return json;
  }