Repository: tinkerpop
Updated Branches:
  refs/heads/master 01d035efa -> 3e4953283


Setting of "version" should be done in the abstract classes as they are 
specific to that version.

Not setting that explicitly and Using the default could leave potential for an 
extending class to get stuck with the wrong version being set. In this case, V2 
would get a V1 setting. CTR


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

Branch: refs/heads/master
Commit: 3e4953283df758394579a0163a3497f319d499b9
Parents: 01d035e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Sep 22 08:36:36 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Sep 22 14:17:02 2016 -0400

----------------------------------------------------------------------
 docs/src/reference/gremlin-applications.asciidoc     |  3 +++
 .../ser/AbstractGraphSONMessageSerializerV1d0.java   | 14 +++++++++++---
 .../ser/AbstractGraphSONMessageSerializerV2d0.java   | 15 ++++++++++++---
 .../ser/GraphSONMessageSerializerGremlinV1d0.java    |  4 ++--
 .../ser/GraphSONMessageSerializerGremlinV2d0.java    |  8 ++------
 .../driver/ser/GraphSONMessageSerializerV1d0.java    |  4 ++--
 .../driver/ser/GraphSONMessageSerializerV2d0.java    |  6 ++----
 7 files changed, 34 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc 
b/docs/src/reference/gremlin-applications.asciidoc
index bff9f0f..2c093fa 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -1387,7 +1387,10 @@ trying to use TinkerPop from non-JVM languages.  JSON 
obviously has wide support
 programming languages and can be consumed by a wide variety of tools.
 
 [source,yaml]
+----
   - { className: 
org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0 }
+  - { className: 
org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0 }
+----
 
 The above configuration represents the default serialization under the 
`application/json` MIME type and produces JSON
 consistent with standard JSON data types.  It has the following configuration 
option:

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
index ac6a74f..e23fc9c 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
@@ -30,6 +30,8 @@ import io.netty.buffer.ByteBufAllocator;
 import io.netty.util.ReferenceCountUtil;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONUtil;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerationException;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
 import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
@@ -61,7 +63,7 @@ public abstract class AbstractGraphSONMessageSerializerV1d0 
extends AbstractMess
     };
 
     public AbstractGraphSONMessageSerializerV1d0() {
-        final GraphSONMapper.Builder builder = 
configureBuilder(GraphSONMapper.build());
+        final GraphSONMapper.Builder builder = 
configureBuilder(initBuilder(null));
         mapper = builder.create().createMapper();
     }
 
@@ -88,12 +90,12 @@ public abstract class AbstractGraphSONMessageSerializerV1d0 
extends AbstractMess
 
             // a graph was found so use the mapper it constructs.  this allows 
graphson to be auto-configured with any
             // custom classes that the implementation allows for
-            initialBuilder = g.io(GraphSONIo.build()).mapper();
+            initialBuilder = initBuilder(g.io(GraphSONIo.build()).mapper());
         } else {
             // no graph was supplied so just use the default - this will 
likely be the case when using a graph
             // with no custom classes or a situation where the user needs 
complete control like when using two
             // distinct implementations each with their own custom classes.
-            initialBuilder = GraphSONMapper.build();
+            initialBuilder = initBuilder(null);
         }
 
         addIoRegistries(config, initialBuilder);
@@ -171,6 +173,12 @@ public abstract class 
AbstractGraphSONMessageSerializerV1d0 extends AbstractMess
         }
     }
 
+    private GraphSONMapper.Builder initBuilder(final GraphSONMapper.Builder 
builder) {
+        final GraphSONMapper.Builder b = null == builder ? 
GraphSONMapper.build() : builder;
+        return b.addCustomModule(new 
AbstractGraphSONMessageSerializerV1d0.GremlinServerModule())
+                .version(GraphSONVersion.V1_0);
+    }
+
     public final static class GremlinServerModule extends SimpleModule {
         public GremlinServerModule() {
             super("graphson-gremlin-server");

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV2d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV2d0.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV2d0.java
index d846a69..52cbda2 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV2d0.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV2d0.java
@@ -29,6 +29,8 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONUtil;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerationException;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
 import org.apache.tinkerpop.shaded.jackson.core.type.TypeReference;
@@ -58,7 +60,7 @@ public abstract class AbstractGraphSONMessageSerializerV2d0 
extends AbstractMess
     };
 
     public AbstractGraphSONMessageSerializerV2d0() {
-        final GraphSONMapper.Builder builder = 
configureBuilder(GraphSONMapper.build());
+        final GraphSONMapper.Builder builder = 
configureBuilder(initBuilder(null));
         mapper = builder.create().createMapper();
     }
 
@@ -85,12 +87,12 @@ public abstract class AbstractGraphSONMessageSerializerV2d0 
extends AbstractMess
 
             // a graph was found so use the mapper it constructs.  this allows 
graphson to be auto-configured with any
             // custom classes that the implementation allows for
-            initialBuilder = g.io(GraphSONIo.build()).mapper();
+            initialBuilder = initBuilder(g.io(GraphSONIo.build()).mapper());
         } else {
             // no graph was supplied so just use the default - this will 
likely be the case when using a graph
             // with no custom classes or a situation where the user needs 
complete control like when using two
             // distinct implementations each with their own custom classes.
-            initialBuilder = GraphSONMapper.build();
+            initialBuilder = initBuilder(null);
         }
 
         addIoRegistries(config, initialBuilder);
@@ -168,6 +170,13 @@ public abstract class 
AbstractGraphSONMessageSerializerV2d0 extends AbstractMess
         }
     }
 
+    private GraphSONMapper.Builder initBuilder(final GraphSONMapper.Builder 
builder) {
+        final GraphSONMapper.Builder b = null == builder ? 
GraphSONMapper.build() : builder;
+        return b.addCustomModule(new 
AbstractGraphSONMessageSerializerV2d0.GremlinServerModule())
+                .addCustomModule(GraphSONXModuleV2d0.build().create(false))
+                .version(GraphSONVersion.V2_0);
+    }
+
     public final static class GremlinServerModule extends SimpleModule {
         public GremlinServerModule() {
             super("graphson-gremlin-server");

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0.java
index c8cf058..3564279 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0.java
@@ -61,8 +61,8 @@ public final class GraphSONMessageSerializerGremlinV1d0 
extends AbstractGraphSON
 
     @Override
     GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder 
builder) {
-        return builder.version(GraphSONVersion.V1_0)
-                .addCustomModule(new 
GraphSONMessageSerializerV1d0.GremlinServerModule())
+        // already set to 1.0 in AbstractGraphSONMessageSerializerV1d0
+        return builder.addCustomModule(new 
GraphSONMessageSerializerV1d0.GremlinServerModule())
                 .embedTypes(true);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV2d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV2d0.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV2d0.java
index be1a26f..9ae4798 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV2d0.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV2d0.java
@@ -19,8 +19,6 @@
 package org.apache.tinkerpop.gremlin.driver.ser;
 
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
 
 import java.nio.ByteBuffer;
@@ -63,9 +61,7 @@ public final class GraphSONMessageSerializerGremlinV2d0 
extends AbstractGraphSON
 
     @Override
     GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder 
builder) {
-        return builder.version(GraphSONVersion.V2_0)
-                .addCustomModule(GraphSONXModuleV2d0.build().create(false))
-                .addCustomModule(new GremlinServerModule())
-                .typeInfo(TypeInfo.PARTIAL_TYPES);
+        // already set to 2.0 in AbstractGraphSONMessageSerializerV2d0
+        return builder.typeInfo(TypeInfo.PARTIAL_TYPES);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0.java
index 7451f6c..e61e946 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0.java
@@ -63,8 +63,8 @@ public final class GraphSONMessageSerializerV1d0 extends 
AbstractGraphSONMessage
 
     @Override
     GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder 
builder) {
-        return builder.version(GraphSONVersion.V1_0)
-                .addCustomModule(new GremlinServerModule())
+        // already set to 1.0 in AbstractGraphSONMessageSerializerV1d0
+        return builder.addCustomModule(new GremlinServerModule())
                 .embedTypes(false);
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e495328/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV2d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV2d0.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV2d0.java
index 4386b5a..89432d9 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV2d0.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV2d0.java
@@ -65,10 +65,8 @@ public final class GraphSONMessageSerializerV2d0 extends 
AbstractGraphSONMessage
 
     @Override
     GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder 
builder) {
-        return builder.version(GraphSONVersion.V2_0)
-                .addCustomModule(GraphSONXModuleV2d0.build().create(false))
-                .addCustomModule(new GremlinServerModule())
-                .typeInfo(TypeInfo.PARTIAL_TYPES);
+        // already set to 2.0 in AbstractGraphSONMessageSerializerV2d0
+        return builder.typeInfo(TypeInfo.PARTIAL_TYPES);
     }
 
     @Override

Reply via email to