You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/04/22 22:01:01 UTC

incubator-tinkerpop git commit: Add GraphReader.readObject and GraphWriter.writeObject.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master df393c074 -> 31d028668


Add GraphReader.readObject and GraphWriter.writeObject.

Not all IO implementations can support this, but for those that can like Gryo it provides a nice abstraction for folks to swap in and out of implementations.  Of course, the preferred way is probably to use the Io.mapper() to get the raw serializer implementation when possible, but for lightweight uses that is probably not necessary.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/31d02866
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/31d02866
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/31d02866

Branch: refs/heads/master
Commit: 31d0286685db53d23afa353c3be483523c526ba2
Parents: df393c0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 22 15:59:12 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 22 15:59:12 2015 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                               |  1 +
 .../gremlin/structure/io/GraphReader.java        | 10 +++++++++-
 .../gremlin/structure/io/GraphWriter.java        | 10 +++++++++-
 .../tinkerpop/gremlin/structure/io/Io.java       | 10 ++++++++++
 .../structure/io/graphml/GraphMLReader.java      | 14 ++++++++++----
 .../structure/io/graphml/GraphMLWriter.java      | 17 +++++++++++------
 .../structure/io/graphson/GraphSONReader.java    |  5 +++++
 .../structure/io/graphson/GraphSONWriter.java    |  5 +++++
 .../io/graphson/LegacyGraphSONReader.java        | 14 ++++++++++----
 .../gremlin/structure/io/gryo/GryoReader.java    | 11 ++++++-----
 .../gremlin/structure/io/gryo/GryoWriter.java    | 13 +++++++------
 .../gremlin/structure/SerializationTest.java     | 19 ++++++++++++-------
 .../structure/util/star/StarGraphTest.java       | 11 ++++++++---
 .../hadoop/structure/io/ObjectWritable.java      |  5 ++++-
 .../hadoop/structure/io/VertexWritable.java      |  2 +-
 15 files changed, 108 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index a49aa7c..4ca9c2a 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ TinkerPop 3.0.0.M9 (NOT OFFICIALLY RELEASED YET)
 
 * `VertexWritable` serializes and deserializes the `StarGraph` object -- no more intermediate `DetachedXXX` objects.
 * Gremlin Server better supports the settings for the high and low watermark that will slow writes to clients that are lagging.
+* Added `GraphReader.readObject()` and `GraphWriter.writeObject` abstractions for those implementations that can support them.
 * Altered `GraphWriter.writeVertices()` method to take an `Iterator` of vertices rather than a `Traversal`.
 * Moved `T` tokens to the `structure/` package as its more general than `process/`.
 * `Attachable.attach()` now takes a `Method` to determine whether to attach via `GET`, `CREATE`, or `GET_OR_CREATE`.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
index 157ee29..e4064b0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
@@ -27,6 +27,7 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Iterator;
 import java.util.function.Function;
 
@@ -71,7 +72,7 @@ public interface GraphReader {
 
     /**
      * Reads a set of vertices from an {@link InputStream} which were written by
-     * {@link GraphWriter#writeVertices(java.io.OutputStream, org.apache.tinkerpop.gremlin.process.traversal.Traversal)}.  This method
+     * {@link GraphWriter#writeVertices(OutputStream, Iterator)}.  This method
      * will read vertex properties as well as edges given the direction supplied as an argument.
      *
      * @param inputStream a stream containing a single vertex as defined by the accompanying {@link GraphWriter}
@@ -97,6 +98,13 @@ public interface GraphReader {
     public Edge readEdge(final InputStream inputStream, final Function<DetachedEdge, Edge> edgeMaker) throws IOException;
 
     /**
+     * Reads an arbitrary object using the standard serializers.
+     *
+     * @param inputStream  a stream containing an object.
+     */
+    public <C> C readObject(final InputStream inputStream, final Class<? extends C> clazz) throws IOException;
+
+    /**
      * Largely a marker interface for builder classes that construct a {@link GraphReader}.
      */
     public interface ReaderBuilder<T extends GraphReader> {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphWriter.java
index 75b030a..a7d7c85 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphWriter.java
@@ -76,7 +76,7 @@ public interface GraphWriter {
      * Write a vertex to a stream without writing its edges.
      *
      * @param outputStream The stream to write to.
-     * @param vertexIterator    A traversal that returns a list of vertices.
+     * @param vertexIterator    A iterator that returns a list of vertices.
      */
     public default void writeVertices(final OutputStream outputStream, final Iterator<Vertex> vertexIterator) throws IOException {
         while (vertexIterator.hasNext()) {
@@ -90,6 +90,14 @@ public interface GraphWriter {
     public void writeEdge(final OutputStream outputStream, final Edge e) throws IOException;
 
     /**
+     * Writes an arbitrary object to the stream.
+     *
+     * @param outputStream The stream to write to
+     * @param object The object to write which will use the standard serializer set
+     */
+    public void writeObject(final OutputStream outputStream, final Object object) throws IOException;
+
+    /**
      * Largely a marker interface for builder classes that construct a {@link GraphWriter}.
      */
     public interface WriterBuilder<T extends GraphWriter> {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Io.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Io.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Io.java
index 942486a..47085e0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Io.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Io.java
@@ -69,6 +69,16 @@ public interface Io<R extends GraphReader.ReaderBuilder, W extends GraphWriter.W
      */
     public void readGraph(final String file) throws IOException;
 
+    public static class Exceptions {
+        public static UnsupportedOperationException readerFormatIsForFullGraphSerializationOnly(final Class<? extends GraphReader> clazz) {
+            return new UnsupportedOperationException(String.format("%s only reads an entire Graph", clazz));
+        }
+
+        public static UnsupportedOperationException writerFormatIsForFullGraphSerializationOnly(final Class<? extends GraphWriter> clazz) {
+            return new UnsupportedOperationException(String.format("%s only writes an entire Graph", clazz));
+        }
+    }
+
     /**
      * Helps to construct an {@link Io} implementation and should be implemented by every such implementation as
      * that class will be passed to {@link Graph#io(Builder)} by the user.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
index f7c7583..a2faa05 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
+import org.apache.tinkerpop.gremlin.structure.io.Io;
 import org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
@@ -75,23 +76,28 @@ public class GraphMLReader implements GraphReader {
     public Iterator<Vertex> readVertices(final InputStream inputStream, final Direction direction,
                                          final Function<DetachedVertex, Vertex> vertexMaker,
                                          final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public Edge readEdge(final InputStream inputStream, final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public Vertex readVertex(final InputStream inputStream, final Function<DetachedVertex, Vertex> vertexMaker) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public Vertex readVertex(final InputStream inputStream, final Direction direction, final Function<DetachedVertex, Vertex> vertexMaker,
                              final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
+    }
+
+    @Override
+    public <C> C readObject(InputStream inputStream, Class<? extends C> clazz) throws IOException {
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
index e2f19d5..7b28f64 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
@@ -18,13 +18,13 @@
  */
 package org.apache.tinkerpop.gremlin.structure.io.graphml;
 
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.io.GraphWriter;
+import org.apache.tinkerpop.gremlin.structure.io.Io;
 import org.apache.tinkerpop.gremlin.structure.util.Comparators;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
@@ -77,27 +77,32 @@ public class GraphMLWriter implements GraphWriter {
 
     @Override
     public void writeVertex(final OutputStream outputStream, final Vertex v, Direction direction) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.writerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public void writeVertex(final OutputStream outputStream, final Vertex v) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.writerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public void writeEdge(final OutputStream outputStream, final Edge e) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.writerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public void writeVertices(final OutputStream outputStream, final Iterator<Vertex> vertexIterator, final Direction direction) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.writerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public void writeVertices(final OutputStream outputStream, final Iterator<Vertex> vertexIterator) throws IOException {
-        throw new UnsupportedOperationException("GraphML does not allow for a partial structure");
+        throw Io.Exceptions.writerFormatIsForFullGraphSerializationOnly(this.getClass());
+    }
+
+    @Override
+    public void writeObject(final OutputStream outputStream, final Object object) throws IOException {
+        throw Io.Exceptions.writerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
index c84dfd6..7c69203 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
@@ -170,6 +170,11 @@ public class GraphSONReader implements GraphReader {
         return v;
     }
 
+    @Override
+    public <C> C readObject(final InputStream inputStream, final Class<? extends C> clazz) throws IOException {
+        return mapper.readValue(inputStream, clazz);
+    }
+
     private static void createVertexProperty(final Graph graphToWriteTo, final Vertex v, final VertexProperty<Object> p) {
         final List<Object> propertyArgs = new ArrayList<>();
         if (graphToWriteTo.features().vertex().properties().supportsUserSuppliedIds())

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java
index 01b1f42..7d1c507 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java
@@ -95,6 +95,11 @@ public class GraphSONWriter implements GraphWriter {
         writer.flush();
     }
 
+    @Override
+    public void writeObject(final OutputStream outputStream, final Object object) throws IOException {
+        this.mapper.writeValue(outputStream, object);
+    }
+
     public static Builder build() {
         return new Builder();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
index b676031..fc02b50 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
+import org.apache.tinkerpop.gremlin.structure.io.Io;
 import org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
@@ -120,22 +121,27 @@ public class LegacyGraphSONReader implements GraphReader {
     public Iterator<Vertex> readVertices(final InputStream inputStream, final Direction direction,
                                          final Function<DetachedVertex, Vertex> vertexMaker,
                                          final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
-        throw new UnsupportedOperationException("This reader only reads an entire Graph");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public Edge readEdge(final InputStream inputStream, final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
-        throw new UnsupportedOperationException("This reader only reads an entire Graph");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public Vertex readVertex(final InputStream inputStream, final Function<DetachedVertex, Vertex> vertexMaker) throws IOException {
-        throw new UnsupportedOperationException("This reader only reads an entire Graph");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     @Override
     public Vertex readVertex(final InputStream inputStream, final Direction direction, final Function<DetachedVertex, Vertex> vertexMaker, final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
-        throw new UnsupportedOperationException("This reader only reads an entire Graph");
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
+    }
+
+    @Override
+    public <C> C readObject(InputStream inputStream, Class<? extends C> clazz) throws IOException {
+        throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
     }
 
     public static Builder build() {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
index 8e136b3..4039f4f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
@@ -197,6 +197,11 @@ public class GryoReader implements GraphReader {
         }
     }
 
+    @Override
+    public <C> C readObject(final InputStream inputStream, final Class<? extends C> clazz) throws IOException{
+        return clazz.cast(this.kryo.readClassAndObject(new Input(inputStream)));
+    }
+
     private static void createVertexProperty(final Graph graphToWriteTo, final Vertex v, final VertexProperty<Object> p) {
         final List<Object> propertyArgs = new ArrayList<>();
         if (graphToWriteTo.features().vertex().properties().supportsUserSuppliedIds())
@@ -282,6 +287,7 @@ public class GryoReader implements GraphReader {
         input.readBytes(13);
     }
 
+
     /**
      * Reads through the all the edges for a vertex and writes the edges to a temp file which will be read later.
      */
@@ -301,7 +307,6 @@ public class GryoReader implements GraphReader {
         kryo.writeClassAndObject(output, VertexTerminator.INSTANCE);
     }
 
-
     /**
      * Read the edges from the temp file and load them to the graph.
      */
@@ -338,10 +343,6 @@ public class GryoReader implements GraphReader {
         }
     }
 
-    public <T> T readObject(final InputStream inputStream) {
-        return (T) this.kryo.readClassAndObject(new Input(inputStream));
-    }
-
     public static Builder build() {
         return new Builder();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java
index e099f20..7efda67 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java
@@ -94,6 +94,13 @@ public class GryoWriter implements GraphWriter {
         output.flush();
     }
 
+    @Override
+    public void writeObject(final OutputStream outputStream, final Object object) {
+        final Output output = new Output(outputStream);
+        this.kryo.writeClassAndObject(output, object);
+        output.flush();
+    }
+
     void writeHeader(final Output output) throws IOException {
         output.writeBytes(GryoMapper.HEADER);
     }
@@ -143,12 +150,6 @@ public class GryoWriter implements GraphWriter {
             kryo.writeClassAndObject(output, EdgeTerminator.INSTANCE);
     }
 
-    public void writeObject(final OutputStream outputStream, final Object object) {
-        final Output output = new Output(outputStream);
-        this.kryo.writeClassAndObject(output, object);
-        output.flush();
-    }
-
     public static Builder build() {
         return new Builder();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
index 5b6b475..fae2df1 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
@@ -29,6 +29,11 @@ import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPath;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
 import org.junit.Test;
 import org.junit.experimental.runners.Enclosed;
 import org.junit.runner.RunWith;
@@ -64,7 +69,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, v);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final Vertex detached = gryoReader.readObject(inputStream);
+            final Vertex detached = gryoReader.readObject(inputStream, DetachedVertex.class);
             assertNotNull(detached);
             assertEquals(v.label(), detached.label());
             assertEquals(v.id(), detached.id());
@@ -84,7 +89,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, e);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final Edge detached = gryoReader.readObject(inputStream);
+            final Edge detached = gryoReader.readObject(inputStream, DetachedEdge.class);
             assertNotNull(detached);
             assertEquals(e.label(), detached.label());
             assertEquals(e.id(), detached.id());
@@ -103,7 +108,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, property);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final Property detached = gryoReader.readObject(inputStream);
+            final Property detached = gryoReader.readObject(inputStream, DetachedProperty.class);
             assertNotNull(detached);
             assertEquals(property.key(), detached.key());
             assertEquals(property.value(), detached.value());
@@ -121,7 +126,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, vertexProperty);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final VertexProperty detached = gryoReader.readObject(inputStream);
+            final VertexProperty detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class);
             assertNotNull(detached);
             assertEquals(vertexProperty.label(), detached.label());
             assertEquals(vertexProperty.id(), detached.id());
@@ -140,7 +145,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, vertexProperty);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final VertexProperty<?> detached = gryoReader.readObject(inputStream);
+            final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class);
 
             assertNotNull(detached);
             assertEquals(vertexProperty.label(), detached.label());
@@ -165,7 +170,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, p);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final Path detached = gryoReader.readObject(inputStream);
+            final Path detached = gryoReader.readObject(inputStream, DetachedPath.class);
             assertNotNull(detached);
             assertEquals(p.labels().size(), detached.labels().size());
             assertEquals(p.labels().get(0).size(), detached.labels().get(0).size());
@@ -210,7 +215,7 @@ public class SerializationTest {
             gryoWriter.writeObject(outputStream, before);
 
             final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-            final TraversalMetrics after = gryoReader.readObject(inputStream);
+            final TraversalMetrics after = gryoReader.readObject(inputStream, TraversalMetrics.class);
             assertNotNull(after);
             assertEquals(before.getMetrics().size(), after.getMetrics().size());
             assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
index 7c77756..3adbbc6 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
@@ -37,6 +37,7 @@ import org.junit.Test;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -53,10 +54,14 @@ import static org.junit.Assert.assertTrue;
  */
 public class StarGraphTest extends AbstractGremlinTest {
 
-    private static Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
+    private static Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph)  {
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         GryoWriter.build().create().writeObject(outputStream, starGraph);
-        return Pair.with(GryoReader.build().create().readObject(new ByteArrayInputStream(outputStream.toByteArray())), outputStream.size());
+        try {
+            return Pair.with(GryoReader.build().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size());
+        } catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        }
     }
 
     @Test
@@ -93,7 +98,7 @@ public class StarGraphTest extends AbstractGremlinTest {
     @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
     @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
     public void shouldHaveSizeOfStarGraphLessThanDetached() throws Exception {
-        final Random random = new Random();
+        final Random random = new Random(95746498l);
         final Vertex vertex = graph.addVertex("person");
         for (int i = 0; i < 100; i++) { // vertex properties and meta properties
             vertex.property(VertexProperty.Cardinality.list, UUID.randomUUID().toString(), random.nextDouble(),

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/ObjectWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/ObjectWritable.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/ObjectWritable.java
index 54c2896..453d38d 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/ObjectWritable.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/ObjectWritable.java
@@ -61,7 +61,10 @@ public final class ObjectWritable<T> implements WritableComparable<ObjectWritabl
     public void readFields(final DataInput input) throws IOException {
         this.t = HadoopPools.GRYO_POOL.doWithReader(gryoReader -> {
             try {
-                return gryoReader.readObject(new ByteArrayInputStream(WritableUtils.readCompressedByteArray(input)));
+                // class argument is Object because gryo doesn't really care that we don't know the specific type.
+                // the type is embedded in the stream so it can just read it from there and return it as needed.
+                // presumably that will cast nicely to T
+                return (T) gryoReader.readObject(new ByteArrayInputStream(WritableUtils.readCompressedByteArray(input)), Object.class);
             } catch (IOException e) {
                 throw new IllegalStateException(e.getMessage(), e);
             }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31d02866/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
index aa66d1a..f13f9e8 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
@@ -63,7 +63,7 @@ public final class VertexWritable implements Writable, Serializable {
             this.vertex = HadoopPools.GRYO_POOL.doWithReader(gryoReader -> {
                 try {
                     final ByteArrayInputStream inputStream = new ByteArrayInputStream(WritableUtils.readCompressedByteArray(input));
-                    return ((StarGraph) gryoReader.readObject(inputStream)).getStarVertex(); // read the star graph
+                    return gryoReader.readObject(inputStream, StarGraph.class).getStarVertex(); // read the star graph
                 } catch (final IOException e) {
                     throw new IllegalStateException(e.getMessage(), e);
                 }