@Override
    public void serialize(
        final TinkerGraph graph,
        final JsonGenerator jsonGenerator,
        final SerializerProvider serializerProvider)
        throws IOException {
      jsonGenerator.writeStartObject();

      jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
      jsonGenerator.writeStartArray();

      final Iterator<Vertex> vertices = graph.vertices();
      while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
      }

      jsonGenerator.writeEndArray();

      jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
      jsonGenerator.writeStartArray();

      final Iterator<Edge> edges = graph.edges();
      while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
      }

      jsonGenerator.writeEndArray();

      jsonGenerator.writeEndObject();
    }
    @Override
    public void serializeWithType(
        final TinkerGraph graph,
        final JsonGenerator jsonGenerator,
        final SerializerProvider serializerProvider,
        final TypeSerializer typeSerializer)
        throws IOException {
      jsonGenerator.writeStartObject();
      jsonGenerator.writeStringField(GraphSONTokens.CLASS, TinkerGraph.class.getName());

      jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
      jsonGenerator.writeStartArray();
      jsonGenerator.writeString(ArrayList.class.getName());
      jsonGenerator.writeStartArray();

      final Iterator<Vertex> vertices = graph.vertices();
      while (vertices.hasNext()) {
        GraphSONUtil.writeWithType(
            vertices.next(), jsonGenerator, serializerProvider, typeSerializer);
      }

      jsonGenerator.writeEndArray();
      jsonGenerator.writeEndArray();

      jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
      jsonGenerator.writeStartArray();
      jsonGenerator.writeString(ArrayList.class.getName());
      jsonGenerator.writeStartArray();

      final Iterator<Edge> edges = graph.edges();
      while (edges.hasNext()) {
        GraphSONUtil.writeWithType(edges.next(), jsonGenerator, serializerProvider, typeSerializer);
      }

      jsonGenerator.writeEndArray();
      jsonGenerator.writeEndArray();

      jsonGenerator.writeEndObject();
    }