tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [1/3] tinkerpop git commit: Turned on more IO tests for graphson 2.0 in test suite.
Date Tue, 23 Aug 2016 18:12:27 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 8e04a6529 -> e5801281f


Turned on more IO tests for graphson 2.0 in test suite.


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

Branch: refs/heads/TINKERPOP-1278
Commit: f7b9b1a0218fb0555915abc2f3293c4806540169
Parents: e6f4cfd
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Tue Aug 23 13:35:38 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Tue Aug 23 13:35:38 2016 -0400

----------------------------------------------------------------------
 .../io/graphson/AbstractObjectDeserializer.java |  4 +-
 .../structure/io/graphson/GraphSONModule.java   | 76 ++++++++++----------
 .../structure/io/graphson/GraphSONReader.java   | 50 ++++++++-----
 .../io/graphson/GraphSONSerializersV2d0.java    | 14 ++--
 .../GraphSONTraversalSerializersV2d0.java       |  2 +-
 .../gremlin/structure/io/IoCustomTest.java      | 19 +++--
 .../gremlin/structure/io/IoEdgeTest.java        | 13 +++-
 .../gremlin/structure/io/IoPropertyTest.java    | 13 +++-
 .../tinkerpop/gremlin/structure/io/IoTest.java  |  2 +-
 .../gremlin/structure/io/IoVertexTest.java      | 13 +++-
 .../gremlin/structure/io/util/CustomId.java     | 75 ++++++++++++++++++-
 .../tinkergraph/TinkerGraphProvider.java        | 30 +++++---
 12 files changed, 222 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
index 5087113..bd7f4b6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
@@ -31,7 +31,7 @@ import java.util.Map;
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
-abstract class AbstractObjectDeserializer<T> extends StdDeserializer<T> {
+public abstract class AbstractObjectDeserializer<T> extends StdDeserializer<T>
{
 
     protected AbstractObjectDeserializer(final Class<T> clazz) {
         super(clazz);
@@ -47,5 +47,5 @@ abstract class AbstractObjectDeserializer<T> extends StdDeserializer<T>
{
         return createObject(mapData);
     }
 
-    abstract T createObject(final Map<String, Object> data);
+    public abstract T createObject(final Map<String, Object> data);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index 21a48f3..e332834 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -40,6 +40,8 @@ import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.star.DirectionalStarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONDeserializer;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV1d0;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV2d0;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
@@ -58,6 +60,7 @@ import java.time.Year;
 import java.time.YearMonth;
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -82,42 +85,43 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
      */
     static final class GraphSONModuleV2d0 extends GraphSONModule {
 
-        private static final LinkedHashMap<Class, String> TYPE_DEFINITIONS = new LinkedHashMap<Class,
String>() {{
-            // Those don't have deserializers because handled by Jackson,
-            // but we still want to rename them in GraphSON
-            put(ByteBuffer.class, "bytebuffer");
-            put(Short.class, "int16");
-            put(Integer.class, "int32");
-            put(Long.class, "int64");
-            put(Double.class, "double");
-            put(Float.class, "float");
-
-            // Time serializers/deserializers
-            put(Duration.class, "duration");
-            put(Instant.class, "instant");
-            put(LocalDate.class, "localdate");
-            put(LocalDateTime.class, "localdatetime");
-            put(LocalTime.class, "localtime");
-            put(MonthDay.class, "monthday");
-            put(OffsetDateTime.class, "offsetdatetime");
-            put(OffsetTime.class, "offsettime");
-            put(Period.class, "period");
-            put(Year.class, "year");
-            put(YearMonth.class, "yearmonth");
-            put(ZonedDateTime.class, "zoneddatetime");
-            put(ZoneOffset.class, "zoneoffset");
-
-            // Tinkerpop Graph objects
-            put(Vertex.class, "vertex");
-            put(Edge.class, "edge");
-            put(Property.class, "property");
-            put(Path.class, "path");
-            put(VertexProperty.class, "vertexproperty");
-            put(Metrics.class, "metrics");
-            put(TraversalMetrics.class, "traversalmetrics");
-            put(Traverser.class, "traverser");
-            put(Tree.class, "tree");
-        }};
+        private static final Map<Class, String> TYPE_DEFINITIONS = Collections.unmodifiableMap(
+                new LinkedHashMap<Class, String>() {{
+                    // Those don't have deserializers because handled by Jackson,
+                    // but we still want to rename them in GraphSON
+                    put(ByteBuffer.class, "bytebuffer");
+                    put(Short.class, "int16");
+                    put(Integer.class, "int32");
+                    put(Long.class, "int64");
+                    put(Double.class, "double");
+                    put(Float.class, "float");
+
+                    // Time serializers/deserializers
+                    put(Duration.class, "duration");
+                    put(Instant.class, "instant");
+                    put(LocalDate.class, "localdate");
+                    put(LocalDateTime.class, "localdatetime");
+                    put(LocalTime.class, "localtime");
+                    put(MonthDay.class, "monthday");
+                    put(OffsetDateTime.class, "offsetdatetime");
+                    put(OffsetTime.class, "offsettime");
+                    put(Period.class, "period");
+                    put(Year.class, "year");
+                    put(YearMonth.class, "yearmonth");
+                    put(ZonedDateTime.class, "zoneddatetime");
+                    put(ZoneOffset.class, "zoneoffset");
+
+                    // Tinkerpop Graph objects
+                    put(Vertex.class, "vertex");
+                    put(Edge.class, "edge");
+                    put(Property.class, "property");
+                    put(Path.class, "path");
+                    put(VertexProperty.class, "vertexproperty");
+                    put(Metrics.class, "metrics");
+                    put(TraversalMetrics.class, "traversalmetrics");
+                    put(Traverser.class, "traverser");
+                    put(Tree.class, "tree");
+                }});
 
         /**
          * Constructs a new object.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/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 0b27c61..667aa86 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
@@ -71,6 +71,7 @@ import java.util.stream.Stream;
 public final class GraphSONReader implements GraphReader {
     private final ObjectMapper mapper;
     private final long batchSize;
+    private final GraphSONVersion version;
     private boolean unwrapAdjacencyList = false;
 
     final TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String,
Object>>() {
@@ -80,6 +81,7 @@ public final class GraphSONReader implements GraphReader {
         mapper = builder.mapper.createMapper();
         batchSize = builder.batchSize;
         unwrapAdjacencyList = builder.unwrapAdjacencyList;
+        version = ((GraphSONMapper)builder.mapper).getVersion();
     }
 
     /**
@@ -191,17 +193,21 @@ public final class GraphSONReader implements GraphReader {
      */
     @Override
     public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>,
Edge> edgeAttachMethod) throws IOException {
-        final Map<String, Object> edgeData = mapper.readValue(inputStream, mapTypeReference);
+        if (version == GraphSONVersion.V1_0) {
+            final Map<String, Object> edgeData = mapper.readValue(inputStream, mapTypeReference);
 
-        final Map<String,Object> edgeProperties = edgeData.containsKey(GraphSONTokens.PROPERTIES)
?
-                (Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES) : Collections.EMPTY_MAP;
-        final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
-                edgeData.get(GraphSONTokens.LABEL).toString(),
-                edgeProperties,
-                Pair.with(edgeData.get(GraphSONTokens.OUT), edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
-                Pair.with(edgeData.get(GraphSONTokens.IN), edgeData.get(GraphSONTokens.IN_LABEL).toString()));
+            final Map<String, Object> edgeProperties = edgeData.containsKey(GraphSONTokens.PROPERTIES)
?
+                    (Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES) :
Collections.EMPTY_MAP;
+            final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
+                    edgeData.get(GraphSONTokens.LABEL).toString(),
+                    edgeProperties,
+                    Pair.with(edgeData.get(GraphSONTokens.OUT), edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
+                    Pair.with(edgeData.get(GraphSONTokens.IN), edgeData.get(GraphSONTokens.IN_LABEL).toString()));
 
-        return edgeAttachMethod.apply(edge);
+            return edgeAttachMethod.apply(edge);
+        } else {
+            return edgeAttachMethod.apply((DetachedEdge) mapper.readValue(inputStream, Edge.class));
+        }
     }
 
     /**
@@ -217,12 +223,16 @@ public final class GraphSONReader implements GraphReader {
     @Override
     public VertexProperty readVertexProperty(final InputStream inputStream,
                                              final Function<Attachable<VertexProperty>,
VertexProperty> vertexPropertyAttachMethod) throws IOException {
-        final Map<String, Object> vpData = mapper.readValue(inputStream, mapTypeReference);
-        final Map<String, Object> metaProperties = (Map<String, Object>) vpData.get(GraphSONTokens.PROPERTIES);
-        final DetachedVertexProperty vp = new DetachedVertexProperty(vpData.get(GraphSONTokens.ID),
-                vpData.get(GraphSONTokens.LABEL).toString(),
-                vpData.get(GraphSONTokens.VALUE), metaProperties);
-        return vertexPropertyAttachMethod.apply(vp);
+        if (version == GraphSONVersion.V1_0) {
+            final Map<String, Object> vpData = mapper.readValue(inputStream, mapTypeReference);
+            final Map<String, Object> metaProperties = (Map<String, Object>)
vpData.get(GraphSONTokens.PROPERTIES);
+            final DetachedVertexProperty vp = new DetachedVertexProperty(vpData.get(GraphSONTokens.ID),
+                    vpData.get(GraphSONTokens.LABEL).toString(),
+                    vpData.get(GraphSONTokens.VALUE), metaProperties);
+            return vertexPropertyAttachMethod.apply(vp);
+        } else {
+            return vertexPropertyAttachMethod.apply((DetachedVertexProperty) mapper.readValue(inputStream,
VertexProperty.class));
+        }
     }
 
     /**
@@ -236,9 +246,13 @@ public final class GraphSONReader implements GraphReader {
     @Override
     public Property readProperty(final InputStream inputStream,
                                  final Function<Attachable<Property>, Property>
propertyAttachMethod) throws IOException {
-        final Map<String, Object> propertyData = mapper.readValue(inputStream, mapTypeReference);
-        final DetachedProperty p = new DetachedProperty(propertyData.get(GraphSONTokens.KEY).toString(),
propertyData.get(GraphSONTokens.VALUE));
-        return propertyAttachMethod.apply(p);
+        if (version == GraphSONVersion.V1_0) {
+            final Map<String, Object> propertyData = mapper.readValue(inputStream,
mapTypeReference);
+            final DetachedProperty p = new DetachedProperty(propertyData.get(GraphSONTokens.KEY).toString(),
propertyData.get(GraphSONTokens.VALUE));
+            return propertyAttachMethod.apply(p);
+        } else {
+            return propertyAttachMethod.apply((DetachedProperty) mapper.readValue(inputStream,
Property.class));
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
index 4e522aa..31ca6a2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
@@ -424,7 +424,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        Vertex createObject(final Map<String, Object> vertexData) {
+        public Vertex createObject(final Map<String, Object> vertexData) {
             return new DetachedVertex(
                     vertexData.get(GraphSONTokens.ID),
                     vertexData.get(GraphSONTokens.LABEL).toString(),
@@ -440,7 +440,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        Edge createObject(final Map<String, Object> edgeData) {
+        public Edge createObject(final Map<String, Object> edgeData) {
             return new DetachedEdge(
                     edgeData.get(GraphSONTokens.ID),
                     edgeData.get(GraphSONTokens.LABEL).toString(),
@@ -458,7 +458,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        Property createObject(final Map<String, Object> propData) {
+        public Property createObject(final Map<String, Object> propData) {
             return new DetachedProperty(
                     (String) propData.get(GraphSONTokens.KEY),
                     propData.get(GraphSONTokens.VALUE));
@@ -472,7 +472,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        Path createObject(final Map<String, Object> pathData) {
+        public Path createObject(final Map<String, Object> pathData) {
             final Path p = MutablePath.make();
 
             final List labels = (List) pathData.get(GraphSONTokens.LABELS);
@@ -492,7 +492,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        VertexProperty createObject(final Map<String, Object> propData) {
+        public VertexProperty createObject(final Map<String, Object> propData) {
             return new DetachedVertexProperty(
                     propData.get(GraphSONTokens.ID),
                     (String) propData.get(GraphSONTokens.LABEL),
@@ -508,7 +508,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        Metrics createObject(final Map<String, Object> metricsData) {
+        public Metrics createObject(final Map<String, Object> metricsData) {
             final MutableMetrics m = new MutableMetrics((String)metricsData.get(GraphSONTokens.ID),
(String)metricsData.get(GraphSONTokens.NAME));
 
             m.setDuration(Math.round((Double) metricsData.get(GraphSONTokens.DURATION) *
1000000), TimeUnit.NANOSECONDS);
@@ -532,7 +532,7 @@ class GraphSONSerializersV2d0 {
         }
 
         @Override
-        TraversalMetrics createObject(final Map<String, Object> traversalMetricsData)
{
+        public TraversalMetrics createObject(final Map<String, Object> traversalMetricsData)
{
             return new DefaultTraversalMetrics(
                     Math.round((Double) traversalMetricsData.get(GraphSONTokens.DURATION)
* 1000000),
                     (List<MutableMetrics>) traversalMetricsData.get(GraphSONTokens.METRICS)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
index d768d8e..080f64d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@ -403,7 +403,7 @@ final class GraphSONTraversalSerializersV2d0 {
         }
 
         @Override
-        Traverser createObject(final Map<String, Object> data) {
+        public Traverser createObject(final Map<String, Object> data) {
             return new DefaultRemoteTraverser<>(data.get(GraphSONTokens.VALUE), (Long)
data.get(GraphSONTokens.BULK));
         }
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
index 699cb11..d89f97e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
@@ -25,6 +25,9 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
 import org.apache.tinkerpop.gremlin.structure.io.util.CustomId;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule;
@@ -52,13 +55,18 @@ public class IoCustomTest extends AbstractGremlinTest {
 
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> data() {
-        final SimpleModule module = new SimpleModule();
-        module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializer());
+        final SimpleModule moduleV1d0 = new SimpleModule();
+        moduleV1d0.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializerV1d0());
+
+        final SimpleModule moduleV2d0 = new CustomId.CustomIdTinkerPopJacksonModule();
 
         return Arrays.asList(new Object[][]{
-                {"graphson-embedded", true,
-                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().addCustomModule(module).embedTypes(true).create()).create(),
-                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().addCustomModule(module).embedTypes(true).create()).create()},
+                {"graphson-v1-embedded", true,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().addCustomModule(moduleV1d0).embedTypes(true).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().addCustomModule(moduleV1d0).embedTypes(true).create()).create()},
+                {"graphson-v2-embedded", true,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().addCustomModule(moduleV2d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().addCustomModule(moduleV2d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
                 {"gryo", true,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().mapper(g.io(IoCore.gryo()).mapper().addCustom(CustomId.class).create()).create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().mapper(g.io(IoCore.gryo()).mapper().addCustom(CustomId.class).create()).create()}
@@ -77,7 +85,6 @@ public class IoCustomTest extends AbstractGremlinTest {
     @Parameterized.Parameter(value = 3)
     public Function<Graph, GraphWriter> writerMaker;
 
-
     @Test
     @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
index e8db127..8d2a58a 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
@@ -24,6 +24,9 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Test;
@@ -51,12 +54,18 @@ public class IoEdgeTest extends AbstractGremlinTest {
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> data() {
         return Arrays.asList(new Object[][]{
-                {"graphson", false, false,
+                {"graphson-v1", false, false,
                         (Function<Graph,GraphReader>) g -> g.io(IoCore.graphson()).reader().create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().create()},
-                {"graphson-embedded", true, true,
+                {"graphson-v1-embedded", true, true,
                         (Function<Graph,GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create()},
+                {"graphson-v2", false, false,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
+                {"graphson-v2-embedded", true, true,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
                 {"gryo", true, true,
                         (Function<Graph,GraphReader>) g -> g.io(IoCore.gryo()).reader().create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().create()}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
index 4077f23..3a3d6f0 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
@@ -23,6 +23,9 @@ import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Property;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,12 +49,18 @@ public class IoPropertyTest extends AbstractGremlinTest {
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> data() {
         return Arrays.asList(new Object[][]{
-                {"graphson", false, false,
+                {"graphson-v1", false, false,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().create()},
-                {"graphson-embedded", true, true,
+                {"graphson-v1-embedded", true, true,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create()},
+                {"graphson-v2", false, false,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
+                {"graphson-v2-embedded", true, true,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
                 {"gryo", true, true,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().create()}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
index 5a624f4..6d21c2b 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
@@ -384,7 +384,7 @@ public class IoTest {
             graph.addVertex(T.id, new CustomId("vertex", id));
 
             final SimpleModule module = new SimpleModule();
-            module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializer());
+            module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializerV1d0());
             final GraphWriter writer = graph.io(graphson).writer().mapper(
                     graph.io(graphson).mapper().addCustomModule(module).embedTypes(true).create()).create();
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
index d457bc5..6e692c4 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
@@ -29,6 +29,9 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.VertexByteArrayInputStream;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -68,12 +71,18 @@ public class IoVertexTest extends AbstractGremlinTest {
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> data() {
         return Arrays.asList(new Object[][]{
-                {"graphson", false, false,
+                {"graphson-v1", false, false,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().create()},
-                {"graphson-embedded", true, false,
+                {"graphson-v1-embedded", true, false,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create()},
+                {"graphson-v2", false, false,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
+                {"graphson-v2-embedded", true, false,
+                        (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+                        (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
                 {"gryo", true, true,
                         (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().create(),
                         (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().create()}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
index 05752a6..2277247 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
@@ -18,7 +18,9 @@
  */
 package org.apache.tinkerpop.gremlin.structure.io.util;
 
+import org.apache.tinkerpop.gremlin.structure.io.graphson.AbstractObjectDeserializer;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TinkerPopJacksonModule;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerationException;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
 import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
@@ -27,6 +29,10 @@ import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer;
 import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
 
 import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.UUID;
 
 /**
@@ -60,8 +66,8 @@ public class CustomId {
         return cluster + ":" + elementId;
     }
 
-    public static class CustomIdJacksonSerializer extends StdSerializer<CustomId> {
-        public CustomIdJacksonSerializer() {
+    public static class CustomIdJacksonSerializerV1d0 extends StdSerializer<CustomId>
{
+        public CustomIdJacksonSerializerV1d0() {
             super(CustomId.class);
         }
 
@@ -88,4 +94,69 @@ public class CustomId {
             jsonGenerator.writeEndObject();
         }
     }
+
+    public static class CustomIdJacksonSerializerV2d0 extends StdSerializer<CustomId>
{
+        public CustomIdJacksonSerializerV2d0() {
+            super(CustomId.class);
+        }
+
+        @Override
+        public void serialize(final CustomId customId, final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider)
+                throws IOException, JsonGenerationException {
+            // when types are not embedded, stringify or resort to JSON primitive representations
of the
+            // type so that non-jvm languages can better interoperate with the TinkerPop
stack.
+            jsonGenerator.writeString(customId.toString());
+        }
+
+        @Override
+        public void serializeWithType(final CustomId customId, final JsonGenerator jsonGenerator,
+                                      final SerializerProvider serializerProvider, final
TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
+            // when the type is included add "class" as a key and then try to utilize as
much of the
+            // default serialization provided by jackson data-bind as possible.  for example,
write
+            // the uuid as an object so that when jackson serializes it, it uses the uuid
serializer
+            // to write it out with the type.  in this way, data-bind should be able to deserialize
+            // it back when types are embedded.
+            typeSerializer.writeTypePrefixForScalar(customId, jsonGenerator);
+            final Map<String, Object> m = new HashMap<>();
+            m.put("cluster", customId.getCluster());
+            m.put("elementId", customId.getElementId());
+            jsonGenerator.writeObject(m);
+            typeSerializer.writeTypeSuffixForScalar(customId, jsonGenerator);
+        }
+    }
+
+    public static class CustomIdJacksonDeserializerV2d0 extends AbstractObjectDeserializer<CustomId>
{
+        public CustomIdJacksonDeserializerV2d0() {
+            super(CustomId.class);
+        }
+
+        @Override
+        public CustomId createObject(final Map data) {
+            return new CustomId((String) data.get("cluster"), (UUID) data.get("elementId"));
+        }
+    }
+
+    public static class CustomIdTinkerPopJacksonModule extends TinkerPopJacksonModule {
+
+        private static final Map<Class, String> TYPE_DEFINITIONS = Collections.unmodifiableMap(
+                new LinkedHashMap<Class, String>() {{
+                    put(CustomId.class, "id");
+                }});
+
+        public CustomIdTinkerPopJacksonModule() {
+            super("custom");
+            addSerializer(CustomId.class, new CustomIdJacksonSerializerV2d0());
+            addDeserializer(CustomId.class, new CustomIdJacksonDeserializerV2d0());
+        }
+
+        @Override
+        public Map<Class, String> getTypeDefinitions() {
+            return TYPE_DEFINITIONS;
+        }
+
+        @Override
+        public String getTypeNamespace() {
+            return "simple";
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
index fcb5fe6..d6dd562 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
@@ -151,22 +151,32 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
                 return TinkerGraph.DefaultIdManager.UUID;
         }  else if (test.equals(IoEdgeTest.class)) {
             final Set<String> testsThatNeedLongIdManager = new HashSet<String>(){{
-                add("shouldReadWriteEdge[graphson]");
-                add("shouldReadWriteDetachedEdgeAsReference[graphson]");
-                add("shouldReadWriteDetachedEdge[graphson]");
+                add("shouldReadWriteEdge[graphson-v1]");
+                add("shouldReadWriteDetachedEdgeAsReference[graphson-v1]");
+                add("shouldReadWriteDetachedEdge[graphson-v1]");
+                add("shouldReadWriteEdge[graphson-v2]");
+                add("shouldReadWriteDetachedEdgeAsReference[graphson-v2]");
+                add("shouldReadWriteDetachedEdge[graphson-v2]");
             }};
 
             if (testsThatNeedLongIdManager.contains(testMethodName))
                 return TinkerGraph.DefaultIdManager.LONG;
         } else if (test.equals(IoVertexTest.class)) {
             final Set<String> testsThatNeedLongIdManager = new HashSet<String>(){{
-                add("shouldReadWriteVertexWithBOTHEdges[graphson]");
-                add("shouldReadWriteVertexWithINEdges[graphson]");
-                add("shouldReadWriteVertexWithOUTEdges[graphson]");
-                add("shouldReadWriteVertexNoEdges[graphson]");
-                add("shouldReadWriteDetachedVertexNoEdges[graphson]");
-                add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson]");
-                add("shouldReadWriteVertexMultiPropsNoEdges[graphson]");
+                add("shouldReadWriteVertexWithBOTHEdges[graphson-v1]");
+                add("shouldReadWriteVertexWithINEdges[graphson-v1]");
+                add("shouldReadWriteVertexWithOUTEdges[graphson-v1]");
+                add("shouldReadWriteVertexNoEdges[graphson-v1]");
+                add("shouldReadWriteDetachedVertexNoEdges[graphson-v1]");
+                add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson-v1]");
+                add("shouldReadWriteVertexMultiPropsNoEdges[graphson-v1]");
+                add("shouldReadWriteVertexWithBOTHEdges[graphson-v2]");
+                add("shouldReadWriteVertexWithINEdges[graphson-v2]");
+                add("shouldReadWriteVertexWithOUTEdges[graphson-v2]");
+                add("shouldReadWriteVertexNoEdges[graphson-v2]");
+                add("shouldReadWriteDetachedVertexNoEdges[graphson-v2]");
+                add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson-v2]");
+                add("shouldReadWriteVertexMultiPropsNoEdges[graphson-v2]");
             }};
 
             if (testsThatNeedLongIdManager.contains(testMethodName))


Mime
View raw message