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 2018/12/14 18:45:53 UTC

[tinkerpop] branch master updated: Backported the most critical changes from #1001

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new b51b1a7  Backported the most critical changes from #1001
     new 03fdb92  Merge branch 'tp33'
b51b1a7 is described below

commit b51b1a7c46b42258cf74180f8c51712970984a45
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Fri Dec 14 13:43:56 2018 -0500

    Backported the most critical changes from #1001
---
 .../graphson/AbstractGraphSONTypeSerializer.java   |  2 +-
 .../io/graphson/GraphSONTypeIdResolver.java        | 32 ++++++++++------------
 2 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTypeSerializer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTypeSerializer.java
index fa90b2c..9d82eef 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTypeSerializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTypeSerializer.java
@@ -82,7 +82,7 @@ public abstract class AbstractGraphSONTypeSerializer extends TypeSerializer {
 
     protected void writeTypePrefix(final JsonGenerator jsonGenerator, final String s) throws IOException {
         jsonGenerator.writeStartObject();
-        jsonGenerator.writeStringField(this.getPropertyName(), s);
+        jsonGenerator.writeStringField(this.propertyName, s);
         jsonGenerator.writeFieldName(this.valuePropertyName);
     }
 
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeIdResolver.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeIdResolver.java
index db2ef5c..fe7ad7a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeIdResolver.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeIdResolver.java
@@ -42,14 +42,6 @@ public class GraphSONTypeIdResolver implements TypeIdResolver {
 
     private final Map<Class, String> typeToId = new HashMap<>();
 
-    public Map<String, JavaType> getIdToType() {
-        return idToType;
-    }
-
-    public Map<Class, String> getTypeToId() {
-        return typeToId;
-    }
-
     // Override manually a type definition.
     public GraphSONTypeIdResolver addCustomType(final String name, final Class clasz) {
         if (Tree.class.isAssignableFrom(clasz)) {
@@ -57,14 +49,22 @@ public class GraphSONTypeIdResolver implements TypeIdResolver {
             // and for which creating a default type is failing because it may fall into a
             // a self-referencing never-ending loop. Temporarily we force Tree<Element>
             // which should cover all the usage TinkerPop would do of the Trees anyway.
-            getIdToType().put(name, TypeFactory.defaultInstance().constructType(new TypeReference<Tree<? extends Element>>() {}));
+            idToType.put(name, TypeFactory.defaultInstance().constructType(new TypeReference<Tree<? extends Element>>() {}));
         } else {
-            getIdToType().put(name, TypeFactory.defaultInstance().constructType(clasz));
+            idToType.put(name, TypeFactory.defaultInstance().constructType(clasz));
         }
-        getTypeToId().put(clasz, name);
+        typeToId.put(clasz, name);
         return this;
     }
 
+    public Map<String, JavaType> getIdToType() {
+        return idToType;
+    }
+
+    public Map<Class, String> getTypeToId() {
+        return typeToId;
+    }
+
     @Override
     public void init(final JavaType javaType) {
     }
@@ -76,13 +76,13 @@ public class GraphSONTypeIdResolver implements TypeIdResolver {
 
     @Override
     public String idFromValueAndType(final Object o, final Class<?> aClass) {
-        if (!getTypeToId().containsKey(aClass)) {
+        if (!typeToId.containsKey(aClass)) {
             // If one wants to serialize an object with a type, but hasn't registered
             // a typeID for that class, fail.
             throw new IllegalArgumentException(String.format("Could not find a type identifier for the class : %s. " +
                     "Make sure the value to serialize has a type identifier registered for its class.", aClass));
         } else {
-            return getTypeToId().get(aClass);
+            return typeToId.get(aClass);
         }
     }
 
@@ -94,15 +94,11 @@ public class GraphSONTypeIdResolver implements TypeIdResolver {
     @Override
     public JavaType typeFromId(final DatabindContext databindContext, final String s) {
         // Get the type from the string from the stored Map. If not found, default to deserialize as a String.
-        return getIdToType().containsKey(s)
-                ? getIdToType().get(s)
-                // TODO: shouldn't we fail instead, if the type is not found? Or log something?
-                : databindContext.constructType(String.class);
+        return idToType.containsKey(s) ? idToType.get(s) : databindContext.constructType(String.class);
     }
 
     @Override
     public String getDescForKnownTypeIds() {
-        // TODO: Not sure what to put here.
         return "GraphSON advanced typing system";
     }