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 2016/08/27 00:55:03 UTC
[48/50] [abbrv] tinkerpop git commit: Fix an issue with Tree
deserialization and the type system.
Fix an issue with Tree deserialization and the type system.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6463cffa
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6463cffa
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6463cffa
Branch: refs/heads/master
Commit: 6463cffa2647b28c0155a19468bac978224bce78
Parents: 99cba4f
Author: Kevin Gallardo <ke...@datastax.com>
Authored: Thu Aug 25 14:08:44 2016 +0100
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 26 17:09:33 2016 -0400
----------------------------------------------------------------------
.../io/graphson/GraphSONTypeIdResolver.java | 14 ++++++++++++--
.../TinkerGraphGraphSONSerializerV2d0Test.java | 19 ++++++-------------
2 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6463cffa/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeIdResolver.java
----------------------------------------------------------------------
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 5ad7265..183e11a 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
@@ -18,7 +18,10 @@
*/
package org.apache.tinkerpop.gremlin.structure.io.graphson;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.shaded.jackson.annotation.JsonTypeInfo;
+import org.apache.tinkerpop.shaded.jackson.core.type.TypeReference;
import org.apache.tinkerpop.shaded.jackson.databind.DatabindContext;
import org.apache.tinkerpop.shaded.jackson.databind.JavaType;
import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeIdResolver;
@@ -49,8 +52,15 @@ public class GraphSONTypeIdResolver implements TypeIdResolver {
// Override manually a type definition.
public GraphSONTypeIdResolver addCustomType(final String name, final Class clasz) {
- // May override types already registered, that's wanted.
- getIdToType().put(name, TypeFactory.defaultInstance().constructType(clasz));
+ if (Tree.class.isAssignableFrom(clasz)) {
+ // there is a special case for Tree which extends a Map, but has only 1 parametrized type,
+ // 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>>() {}));
+ } else {
+ getIdToType().put(name, TypeFactory.defaultInstance().constructType(clasz));
+ }
getTypeToId().put(clasz, name);
return this;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6463cffa/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
index d668d9a..d6eda48 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
@@ -472,30 +472,23 @@ public class TinkerGraphGraphSONSerializerV2d0Test {
}
@Test
- public void deserializersTree() {
+ public void deserializersTestsTree() {
final TinkerGraph tg = TinkerFactory.createModern();
- final GraphWriter writer = getWriter(noTypesMapperV2d0);
- final GraphReader reader = getReader(noTypesMapperV2d0);
+ final GraphWriter writer = getWriter(defaultMapperV2d0);
+ final GraphReader reader = getReader(defaultMapperV2d0);
final Tree t = tg.traversal().V().out().out().tree().next();
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
- final Vertex v = tg.traversal().V(1).next();
- v.property("myUUIDprop", UUID.randomUUID());
- writer.writeObject(out, v);
-
-
-// writer.writeObject(out, t);
+ writer.writeObject(out, t);
final String json = out.toString();
- //System.out.println("json = " + json);
-
-// Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
//Map's equals should check each component of the tree recursively
//on each it will call "equals()" which for Vertices will compare ids, which
//is ok. Complete vertex deser is checked elsewhere.
-// assertEquals(t, treeRead);
+ assertEquals(t, treeRead);
} catch (IOException e) {
e.printStackTrace();