org.apache.tinkerpop.gremlin.structure.io.graphson

## Class GraphSONWriter

- java.lang.Object
- - org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter

- All Implemented Interfaces:
    GraphWriter

      public final class GraphSONWriter
      extends Object
      implements GraphWriter

  A @{link GraphWriter} that writes a graph and its elements to a JSON-based representation. This implementation only supports JSON data types and is therefore lossy with respect to data types (e.g. a float will become a double). Further note that serialized `Map` objects do not support complex types for keys. `Edge` and `Vertex` objects are serialized to `Map` instances. If an `Element` is used as a key, it is coerced to its identifier. Other complex objects are converted via `Object.toString()` unless a mapper serializer is supplied.
  Author:
    Stephen Mallette (http://stephen.genoprime.com)

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `GraphSONWriter.Builder`

    - ### Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.io.GraphWriter

      `GraphWriter.WriterBuilder<T extends GraphWriter>`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static GraphSONWriter.Builder` | `build()`
    `void` | `writeEdge(OutputStream outputStream, Edge e)` Writes an `Edge` object to the stream.
    `void` | `writeGraph(OutputStream outputStream, Graph g)` Writes a `Graph` to stream in an adjacency list format where vertices are written with edges from both directions.
    `void` | `writeObject(OutputStream outputStream, Object object)` Writes an arbitrary object to the stream.
    `void` | `writeProperty(OutputStream outputStream, Property p)` Write a `Property` object to the stream.
    `void` | `writeVertex(OutputStream outputStream, Vertex v)` Writes a single `Vertex` with no edges serialized.
    `void` | `writeVertex(OutputStream outputStream, Vertex v, Direction direction)` Writes a single `Vertex` to stream where edges only from the specified direction are written.
    `void` | `writeVertexProperty(OutputStream outputStream, VertexProperty vp)` Write a `VertexProperty` object to the stream.
    `void` | `writeVertices(OutputStream outputStream, Iterator<Vertex> vertexIterator)` Writes a list of vertices without edges.
    `void` | `writeVertices(OutputStream outputStream, Iterator<Vertex> vertexIterator, Direction direction)` Writes a list of vertices in adjacency list format where vertices are written with edges from both directions.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### writeGraph

          public void writeGraph(OutputStream outputStream,
                                 Graph g)
                          throws IOException

      Writes a `Graph` to stream in an adjacency list format where vertices are written with edges from both directions. Under this serialization model, edges are grouped by label.
      Specified by:
        `writeGraph` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `g` - the graph to write to stream.
      Throws:
        `IOException`

    - #### writeVertex

          public void writeVertex(OutputStream outputStream,
                                  Vertex v,
                                  Direction direction)
                           throws IOException

      Writes a single `Vertex` to stream where edges only from the specified direction are written. Under this serialization model, edges are grouped by label.
      Specified by:
        `writeVertex` in interface `GraphWriter`
      Parameters:
        `direction` - the direction of edges to write or null if no edges are to be written.
        `outputStream` - the stream to write to.
        `v` - the vertex to write.
      Throws:
        `IOException`

    - #### writeVertex

          public void writeVertex(OutputStream outputStream,
                                  Vertex v)
                           throws IOException

      Writes a single `Vertex` with no edges serialized.
      Specified by:
        `writeVertex` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `v` - the vertex to write.
      Throws:
        `IOException`

    - #### writeVertices

          public void writeVertices(OutputStream outputStream,
                                    Iterator<Vertex> vertexIterator,
                                    Direction direction)
                             throws IOException

      Writes a list of vertices in adjacency list format where vertices are written with edges from both directions. Under this serialization model, edges are grouped by label.
      Specified by:
        `writeVertices` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `vertexIterator` - a traversal that returns a list of vertices.
        `direction` - if direction is null then no edges are written.
      Throws:
        `IOException`

    - #### writeVertices

          public void writeVertices(OutputStream outputStream,
                                    Iterator<Vertex> vertexIterator)
                             throws IOException

      Writes a list of vertices without edges.
      Specified by:
        `writeVertices` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `vertexIterator` - a iterator that returns a list of vertices.
      Throws:
        `IOException`

    - #### writeEdge

          public void writeEdge(OutputStream outputStream,
                                Edge e)
                         throws IOException

      Writes an `Edge` object to the stream. Note that this format is different from the format of an `Edge` when serialized with a `Vertex` as done with `writeVertex(OutputStream, Vertex, Direction)` or `writeVertices(OutputStream, Iterator, Direction)` in that the edge label is part of the object and vertex labels are included with their identifiers.
      Specified by:
        `writeEdge` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `e` - the edge to write.
      Throws:
        `IOException`

    - #### writeVertexProperty

          public void writeVertexProperty(OutputStream outputStream,
                                          VertexProperty vp)
                                   throws IOException

      Write a `VertexProperty` object to the stream.
      Specified by:
        `writeVertexProperty` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `vp` - the vertex property to write.
      Throws:
        `IOException`

    - #### writeProperty

          public void writeProperty(OutputStream outputStream,
                                    Property p)
                             throws IOException

      Write a `Property` object to the stream.
      Specified by:
        `writeProperty` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to.
        `p` - the property to write.
      Throws:
        `IOException`

    - #### writeObject

          public void writeObject(OutputStream outputStream,
                                  Object object)
                           throws IOException

      Writes an arbitrary object to the stream. Note that Gremlin Server uses this method when serializing output, thus the format of the GraphSON for a `Vertex` will be somewhat different from the format supplied when using `writeVertex(OutputStream, Vertex, Direction)`. For example, edges will never be included.
      Specified by:
        `writeObject` in interface `GraphWriter`
      Parameters:
        `outputStream` - the stream to write to
        `object` - the object to write which will use the standard serializer set
      Throws:
        `IOException`

    - #### build

          public static GraphSONWriter.Builder build()

Copyright © 2013–2020 Apache Software Foundation. All rights reserved.