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/13 13:07:23 UTC

[5/5] incubator-tinkerpop git commit: Simplify the IoTest.CustomIdJacksonSerializer code a little bit.

Simplify the IoTest.CustomIdJacksonSerializer code a little bit.

Serialization really does fall into two categories now typed and non-typed - the code is very different between them.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 4a06aaf1c855b41b4fedf0865a06c1975cb2f28d
Parents: b1e30ff
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Apr 13 07:03:22 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Apr 13 07:03:22 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/IoTest.java     | 34 ++++++++------------
 1 file changed, 13 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4a06aaf1/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
index 94993ec..bf36d54 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
@@ -2574,32 +2574,24 @@ public class IoTest extends AbstractGremlinTest {
             @Override
             public void serialize(final CustomId customId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
                     throws IOException, JsonGenerationException {
-                ser(customId, jsonGenerator, false);
+                // 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 {
-                ser(customId, jsonGenerator, true);
-            }
-
-            private void ser(final CustomId customId, final JsonGenerator jsonGenerator, final boolean includeType) throws IOException {
-                if (includeType) {
-                    // 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.
-                    jsonGenerator.writeStartObject();
-                    jsonGenerator.writeStringField(GraphSONTokens.CLASS, CustomId.class.getName());
-                    jsonGenerator.writeStringField("cluster", customId.getCluster());
-                    jsonGenerator.writeObjectField("elementId", customId.getElementId());
-                    jsonGenerator.writeEndObject();
-                } else {
-                    // 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());
-                }
+                // 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.
+                jsonGenerator.writeStartObject();
+                jsonGenerator.writeStringField(GraphSONTokens.CLASS, CustomId.class.getName());
+                jsonGenerator.writeStringField("cluster", customId.getCluster());
+                jsonGenerator.writeObjectField("elementId", customId.getElementId());
+                jsonGenerator.writeEndObject();
             }
         }
     }