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 serializedMapobjects do not support complex types for keys.EdgeandVertexobjects are serialized toMapinstances. If anElementis used as a key, it is coerced to its identifier. Other complex objects are converted viaObject.toString()unless a mapper serializer is supplied.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classGraphSONWriter.Builder- 
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.io.GraphWriterGraphWriter.WriterBuilder<T extends GraphWriter>
 
- 
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GraphSONWriter.Builderbuild()voidwriteEdge(OutputStream outputStream, Edge e)Writes anEdgeobject to the stream.voidwriteGraph(OutputStream outputStream, Graph g)Writes aGraphto stream in an adjacency list format where vertices are written with edges from both directions.voidwriteObject(OutputStream outputStream, Object object)Writes an arbitrary object to the stream.voidwriteProperty(OutputStream outputStream, Property p)Write aPropertyobject to the stream.voidwriteVertex(OutputStream outputStream, Vertex v)Writes a singleVertexwith no edges serialized.voidwriteVertex(OutputStream outputStream, Vertex v, Direction direction)Writes a singleVertexto stream where edges only from the specified direction are written.voidwriteVertexProperty(OutputStream outputStream, VertexProperty vp)Write aVertexPropertyobject to the stream.voidwriteVertices(OutputStream outputStream, Iterator<Vertex> vertexIterator)Writes a list of vertices without edges.voidwriteVertices(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.
 
- 
- 
- 
Method Detail- 
writeGraphpublic void writeGraph(OutputStream outputStream, Graph g) throws IOException Writes aGraphto 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:
- writeGraphin interface- GraphWriter
- Parameters:
- outputStream- the stream to write to.
- g- the graph to write to stream.
- Throws:
- IOException
 
 - 
writeVertexpublic void writeVertex(OutputStream outputStream, Vertex v, Direction direction) throws IOException Writes a singleVertexto stream where edges only from the specified direction are written. Under this serialization model, edges are grouped by label.- Specified by:
- writeVertexin 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
 
 - 
writeVertexpublic void writeVertex(OutputStream outputStream, Vertex v) throws IOException Writes a singleVertexwith no edges serialized.- Specified by:
- writeVertexin interface- GraphWriter
- Parameters:
- outputStream- the stream to write to.
- v- the vertex to write.
- Throws:
- IOException
 
 - 
writeVerticespublic 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:
- writeVerticesin 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
 
 - 
writeVerticespublic void writeVertices(OutputStream outputStream, Iterator<Vertex> vertexIterator) throws IOException Writes a list of vertices without edges.- Specified by:
- writeVerticesin interface- GraphWriter
- Parameters:
- outputStream- the stream to write to.
- vertexIterator- a iterator that returns a list of vertices.
- Throws:
- IOException
 
 - 
writeEdgepublic void writeEdge(OutputStream outputStream, Edge e) throws IOException Writes anEdgeobject to the stream. Note that this format is different from the format of anEdgewhen serialized with aVertexas done withwriteVertex(OutputStream, Vertex, Direction)orwriteVertices(OutputStream, Iterator, Direction)in that the edge label is part of the object and vertex labels are included with their identifiers.- Specified by:
- writeEdgein interface- GraphWriter
- Parameters:
- outputStream- the stream to write to.
- e- the edge to write.
- Throws:
- IOException
 
 - 
writeVertexPropertypublic void writeVertexProperty(OutputStream outputStream, VertexProperty vp) throws IOException Write aVertexPropertyobject to the stream.- Specified by:
- writeVertexPropertyin interface- GraphWriter
- Parameters:
- outputStream- the stream to write to.
- vp- the vertex property to write.
- Throws:
- IOException
 
 - 
writePropertypublic void writeProperty(OutputStream outputStream, Property p) throws IOException Write aPropertyobject to the stream.- Specified by:
- writePropertyin interface- GraphWriter
- Parameters:
- outputStream- the stream to write to.
- p- the property to write.
- Throws:
- IOException
 
 - 
writeObjectpublic 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 aVertexwill be somewhat different from the format supplied when usingwriteVertex(OutputStream, Vertex, Direction). For example, edges will never be included.- Specified by:
- writeObjectin interface- GraphWriter
- Parameters:
- outputStream- the stream to write to
- object- the object to write which will use the standard serializer set
- Throws:
- IOException
 
 - 
buildpublic static GraphSONWriter.Builder build() 
 
- 
 
-