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/23 10:44:19 UTC
[1/4] tinkerpop git commit: Renamed traversal serializer class to
include version suffix.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1278 36db3ef9e -> 098b81f78
Renamed traversal serializer class to include version suffix.
Removed public accessor from all serializers classes.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/4eff70d6
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/4eff70d6
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/4eff70d6
Branch: refs/heads/TINKERPOP-1278
Commit: 4eff70d603eaa816d86561ca0c9a5f5f07ed9a8e
Parents: 36db3ef
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 06:12:29 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 06:12:29 2016 -0400
----------------------------------------------------------------------
.../structure/io/graphson/GraphSONModule.java | 82 ++--
.../io/graphson/GraphSONSerializersV2d0.java | 2 +-
.../graphson/GraphSONTraversalSerializers.java | 424 -------------------
.../GraphSONTraversalSerializersV2d0.java | 424 +++++++++++++++++++
4 files changed, 466 insertions(+), 466 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4eff70d6/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 f65d64f..3fe4a70 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
@@ -125,21 +125,21 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
// traversal
// TODO: review (added for integration with new GraphSON model for GLV bytecode)
- addSerializer(Traversal.class, new GraphSONTraversalSerializers.TraversalJacksonSerializer());
- addSerializer(Bytecode.class, new GraphSONTraversalSerializers.BytecodeJacksonSerializer());
- addSerializer(VertexProperty.Cardinality.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Column.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Direction.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(SackFunctions.Barrier.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Operator.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Order.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Pop.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Scope.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(T.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(P.class, new GraphSONTraversalSerializers.PJacksonSerializer());
- addSerializer(Lambda.class, new GraphSONTraversalSerializers.LambdaJacksonSerializer());
- addSerializer(Bytecode.Binding.class, new GraphSONTraversalSerializers.BindingJacksonSerializer());
- addSerializer(Traverser.class, new GraphSONTraversalSerializers.TraverserSerializer());
+ addSerializer(Traversal.class, new GraphSONTraversalSerializersV2d0.TraversalJacksonSerializer());
+ addSerializer(Bytecode.class, new GraphSONTraversalSerializersV2d0.BytecodeJacksonSerializer());
+ addSerializer(VertexProperty.Cardinality.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Column.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Direction.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(SackFunctions.Barrier.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Operator.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Order.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Pop.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Scope.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(T.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(P.class, new GraphSONTraversalSerializersV2d0.PJacksonSerializer());
+ addSerializer(Lambda.class, new GraphSONTraversalSerializersV2d0.LambdaJacksonSerializer());
+ addSerializer(Bytecode.Binding.class, new GraphSONTraversalSerializersV2d0.BindingJacksonSerializer());
+ addSerializer(Traverser.class, new GraphSONTraversalSerializersV2d0.TraverserSerializer());
/////////////////////// DESERIALIZERS ////////////////////////////
@@ -169,12 +169,12 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
addDeserializer(ZoneOffset.class, new JavaTimeSerializersV2d0.ZoneOffsetJacksonDeserializer());
// traversal
- addDeserializer(Bytecode.class, new GraphSONTraversalSerializers.BytecodeJacksonDeserializer());
- addDeserializer(Enum.class, new GraphSONTraversalSerializers.EnumJacksonDeserializer());
- addDeserializer(P.class, new GraphSONTraversalSerializers.PJacksonDeserializer());
- addDeserializer(Lambda.class, new GraphSONTraversalSerializers.LambdaJacksonDeserializer());
- addDeserializer(Bytecode.Binding.class, new GraphSONTraversalSerializers.BindingJacksonDeserializer());
- addDeserializer(Traverser.class, new GraphSONTraversalSerializers.TraverserJacksonDeserializer());
+ addDeserializer(Bytecode.class, new GraphSONTraversalSerializersV2d0.BytecodeJacksonDeserializer());
+ addDeserializer(Enum.class, new GraphSONTraversalSerializersV2d0.EnumJacksonDeserializer());
+ addDeserializer(P.class, new GraphSONTraversalSerializersV2d0.PJacksonDeserializer());
+ addDeserializer(Lambda.class, new GraphSONTraversalSerializersV2d0.LambdaJacksonDeserializer());
+ addDeserializer(Bytecode.Binding.class, new GraphSONTraversalSerializersV2d0.BindingJacksonDeserializer());
+ addDeserializer(Traverser.class, new GraphSONTraversalSerializersV2d0.TraverserJacksonDeserializer());
}
public static Builder build() {
@@ -293,27 +293,27 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
// traversal
// TODO: review (added for integration with new GraphSON model for GLV bytecode)
- addSerializer(Traversal.class, new GraphSONTraversalSerializers.TraversalJacksonSerializer());
- addSerializer(Bytecode.class, new GraphSONTraversalSerializers.BytecodeJacksonSerializer());
- addSerializer(VertexProperty.Cardinality.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Column.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Direction.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(SackFunctions.Barrier.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Operator.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Order.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Pop.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(Scope.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(T.class, new GraphSONTraversalSerializers.EnumJacksonSerializer());
- addSerializer(P.class, new GraphSONTraversalSerializers.PJacksonSerializer());
- addSerializer(Lambda.class, new GraphSONTraversalSerializers.LambdaJacksonSerializer());
- addSerializer(Bytecode.Binding.class, new GraphSONTraversalSerializers.BindingJacksonSerializer());
- addSerializer(Traverser.class, new GraphSONTraversalSerializers.TraverserSerializer());
+ addSerializer(Traversal.class, new GraphSONTraversalSerializersV2d0.TraversalJacksonSerializer());
+ addSerializer(Bytecode.class, new GraphSONTraversalSerializersV2d0.BytecodeJacksonSerializer());
+ addSerializer(VertexProperty.Cardinality.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Column.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Direction.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(SackFunctions.Barrier.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Operator.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Order.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Pop.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(Scope.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(T.class, new GraphSONTraversalSerializersV2d0.EnumJacksonSerializer());
+ addSerializer(P.class, new GraphSONTraversalSerializersV2d0.PJacksonSerializer());
+ addSerializer(Lambda.class, new GraphSONTraversalSerializersV2d0.LambdaJacksonSerializer());
+ addSerializer(Bytecode.Binding.class, new GraphSONTraversalSerializersV2d0.BindingJacksonSerializer());
+ addSerializer(Traverser.class, new GraphSONTraversalSerializersV2d0.TraverserSerializer());
// -- deserializers for traversal
- addDeserializer(Bytecode.class, new GraphSONTraversalSerializers.BytecodeJacksonDeserializer());
- addDeserializer(Enum.class, new GraphSONTraversalSerializers.EnumJacksonDeserializer());
- addDeserializer(P.class, new GraphSONTraversalSerializers.PJacksonDeserializer());
- addDeserializer(Lambda.class, new GraphSONTraversalSerializers.LambdaJacksonDeserializer());
- addDeserializer(Bytecode.Binding.class, new GraphSONTraversalSerializers.BindingJacksonDeserializer());
+ addDeserializer(Bytecode.class, new GraphSONTraversalSerializersV2d0.BytecodeJacksonDeserializer());
+ addDeserializer(Enum.class, new GraphSONTraversalSerializersV2d0.EnumJacksonDeserializer());
+ addDeserializer(P.class, new GraphSONTraversalSerializersV2d0.PJacksonDeserializer());
+ addDeserializer(Lambda.class, new GraphSONTraversalSerializersV2d0.LambdaJacksonDeserializer());
+ addDeserializer(Bytecode.Binding.class, new GraphSONTraversalSerializersV2d0.BindingJacksonDeserializer());
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4eff70d6/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 f6a2f89..a53000a 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
@@ -71,7 +71,7 @@ import static org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONUtil.sa
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class GraphSONSerializersV2d0 {
+class GraphSONSerializersV2d0 {
private GraphSONSerializersV2d0() {
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4eff70d6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java
deleted file mode 100644
index ea47d54..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.structure.io.graphson;
-
-import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser;
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Operator;
-import org.apache.tinkerpop.gremlin.process.traversal.Order;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
-import org.apache.tinkerpop.gremlin.process.traversal.Pop;
-import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
-import org.apache.tinkerpop.gremlin.process.traversal.Scope;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
-import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
-import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
-import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
-import org.apache.tinkerpop.gremlin.structure.Column;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.util.function.Lambda;
-import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
-import org.apache.tinkerpop.shaded.jackson.core.JsonParser;
-import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
-import org.apache.tinkerpop.shaded.jackson.core.ObjectCodec;
-import org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext;
-import org.apache.tinkerpop.shaded.jackson.databind.JsonNode;
-import org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider;
-import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer;
-import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer;
-import org.apache.tinkerpop.shaded.jackson.databind.node.JsonNodeType;
-import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class GraphSONTraversalSerializers {
-
- private GraphSONTraversalSerializers() {
- }
-
- /////////////////
- // SERIALIZERS //
- ////////////////
-
- final static class TraversalJacksonSerializer extends StdSerializer<Traversal> {
-
- public TraversalJacksonSerializer() {
- super(Traversal.class);
- }
-
- @Override
- public void serialize(final Traversal traversal, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- jsonGenerator.writeObject(traversal.asAdmin().getBytecode());
- }
-
- }
-
- final static class BytecodeJacksonSerializer extends StdSerializer<Bytecode> {
-
- public BytecodeJacksonSerializer() {
- super(Bytecode.class);
- }
-
- @Override
- public void serialize(final Bytecode bytecode, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Bytecode");
- if (bytecode.getSourceInstructions().iterator().hasNext()) {
- jsonGenerator.writeArrayFieldStart("source");
- for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) {
- jsonGenerator.writeStartArray();
- jsonGenerator.writeString(instruction.getOperator());
- for (final Object argument : instruction.getArguments()) {
- jsonGenerator.writeObject(argument);
- }
- jsonGenerator.writeEndArray();
- }
- jsonGenerator.writeEndArray();
- }
- if (bytecode.getStepInstructions().iterator().hasNext()) {
- jsonGenerator.writeArrayFieldStart("step");
- for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) {
- jsonGenerator.writeStartArray();
- jsonGenerator.writeString(instruction.getOperator());
- for (final Object argument : instruction.getArguments()) {
- jsonGenerator.writeObject(argument);
- }
- jsonGenerator.writeEndArray();
- }
- jsonGenerator.writeEndArray();
- }
-
- jsonGenerator.writeEndObject();
- }
- }
-
- final static class EnumJacksonSerializer extends StdSerializer<Enum> {
-
- public EnumJacksonSerializer() {
- super(Enum.class);
- }
-
- @Override
- public void serialize(final Enum enumInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeObjectField("@type", enumInstance.getDeclaringClass().getSimpleName());
- jsonGenerator.writeObjectField("value", enumInstance.name());
- jsonGenerator.writeEndObject();
- }
-
- }
-
- final static class PJacksonSerializer extends StdSerializer<P> {
-
- public PJacksonSerializer() {
- super(P.class);
- }
-
- @Override
- public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "P");
- jsonGenerator.writeStringField("predicate", p instanceof ConnectiveP ? p instanceof AndP ? "and" : "or" : p.getBiPredicate().toString());
- jsonGenerator.writeObjectField("value", p instanceof ConnectiveP ? ((ConnectiveP) p).getPredicates() : p.getValue());
- jsonGenerator.writeEndObject();
- }
-
- }
-
- final static class LambdaJacksonSerializer extends StdSerializer<Lambda> {
-
- public LambdaJacksonSerializer() {
- super(Lambda.class);
- }
-
- @Override
- public void serialize(final Lambda lambda, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Lambda");
- jsonGenerator.writeStringField("value", lambda.getLambdaScript());
- jsonGenerator.writeStringField("language", lambda.getLambdaLanguage());
- jsonGenerator.writeNumberField("arguments", lambda.getLambdaArguments());
- jsonGenerator.writeEndObject();
- }
-
- }
-
- final static class BindingJacksonSerializer extends StdSerializer<Bytecode.Binding> {
-
- public BindingJacksonSerializer() {
- super(Bytecode.Binding.class);
- }
-
- @Override
- public void serialize(final Bytecode.Binding binding, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Binding");
- jsonGenerator.writeStringField("variable", binding.variable());
- jsonGenerator.writeObjectField("value", binding.value());
- jsonGenerator.writeEndObject();
- }
-
- }
-
- final static class TraverserSerializer extends StdSerializer<Traverser> {
-
- public TraverserSerializer() {
- super(Traverser.class);
- }
-
- @Override
- public void serialize(final Traverser traverserInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
- throws IOException {
- ser(traverserInstance, jsonGenerator);
- }
-
- @Override
- public void serializeWithType(final Traverser traverser, final JsonGenerator jsonGenerator,
- final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
- ser(traverser, jsonGenerator);
- }
-
- private void ser(final Traverser traverserInstance, final JsonGenerator jsonGenerator) throws IOException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Traverser");
- jsonGenerator.writeObjectField("bulk", traverserInstance.bulk());
- jsonGenerator.writeObjectField("value", traverserInstance.get());
- jsonGenerator.writeEndObject();
- }
- }
-
- ///////////////////
- // DESERIALIZERS //
- //////////////////
-
- final static class BytecodeJacksonDeserializer extends StdDeserializer<Bytecode> {
-
- public BytecodeJacksonDeserializer() {
- super(Bytecode.class);
- }
-
- private static void processInstruction(final JsonNode instruction, final ObjectCodec oc, final Bytecode bytecode, final boolean source) throws IOException {
- final String operator = instruction.get(0).textValue();
- final List<Object> arguments = new ArrayList<>();
- for (int j = 1; j < instruction.size(); j++) {
- final JsonNode argument = instruction.get(j);
- if (argument.getNodeType().equals(JsonNodeType.OBJECT)) {
- if (argument.has("@type")) {
- final String type = argument.get("@type").textValue();
- if (type.equals("Bytecode"))
- arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class));
- else if (type.equals("Binding"))
- arguments.add(oc.readValue(argument.traverse(oc), Bytecode.Binding.class));
- else if (type.equals("P"))
- arguments.add(oc.readValue(argument.traverse(oc), P.class));
- else if (type.equals("Lambda"))
- arguments.add(oc.readValue(argument.traverse(oc), Lambda.class));
- else
- arguments.add(oc.readValue(argument.traverse(oc), Enum.class));
- } else {
- arguments.add(oc.readValue(argument.traverse(oc), Object.class)); // TODO: vertices/edges/etc. don't get processed correctly
- }
- } else if (argument.getNodeType().equals(JsonNodeType.NUMBER)) {
- arguments.add(argument.asInt()); // TODO
- } else if (argument.getNodeType().equals(JsonNodeType.STRING)) {
- arguments.add(argument.textValue());
- } else if (argument.getNodeType().equals(JsonNodeType.BOOLEAN)) {
- arguments.add(argument.booleanValue());
- } else if (argument.getNodeType().equals(JsonNodeType.ARRAY)) {
- final List<Object> list = new ArrayList<>();
- for (int k = 0; k < argument.size(); k++) {
- list.add(oc.readValue(argument.get(k).traverse(oc), Object.class));
- //list.add(argument.get(k).textValue());
- }
- arguments.add(list);
- } else {
- throw new IOException("Unknown argument: " + argument);
- }
- }
- if (source)
- bytecode.addSource(operator, arguments.toArray());
- else
- bytecode.addStep(operator, arguments.toArray());
- }
-
- @Override
- public Bytecode deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
- final Bytecode bytecode = new Bytecode();
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Bytecode");
- if (node.has("source")) {
- final JsonNode source = node.get("source");
- for (int i = 0; i < source.size(); i++) {
- processInstruction(source.get(i), oc, bytecode, true);
- }
- }
- if (node.has("step")) {
- final JsonNode step = node.get("step");
- for (int i = 0; i < step.size(); i++) {
- processInstruction(step.get(i), oc, bytecode, false);
-
- }
- }
- return bytecode;
- }
- }
-
- final static class EnumJacksonDeserializer extends StdDeserializer<Enum> {
-
- public EnumJacksonDeserializer() {
- super(Enum.class);
- }
-
- @Override
- public Enum deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
-
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- final String type = node.get("@type").textValue();
- if (type.equals("Cardinality"))
- return VertexProperty.Cardinality.valueOf(node.get("value").textValue());
- else if (type.equals("Column"))
- return Column.valueOf(node.get("value").textValue());
- else if (type.equals("Direction"))
- return Direction.valueOf(node.get("value").textValue());
- else if (type.equals("Barrier"))
- return SackFunctions.Barrier.valueOf(node.get("value").textValue());
- else if (type.equals("Operator"))
- return Operator.valueOf(node.get("value").textValue());
- else if (type.equals("Order"))
- return Order.valueOf(node.get("value").textValue());
- else if (type.equals("Pop"))
- return Pop.valueOf(node.get("value").textValue());
- else if (type.equals("Scope"))
- return Scope.valueOf(node.get("value").textValue());
- else if (type.equals("T"))
- return T.valueOf(node.get("value").textValue());
- else
- throw new IOException("Unknown enum type: " + type);
-
- }
- }
-
- final static class PJacksonDeserializer extends StdDeserializer<P> {
-
- public PJacksonDeserializer() {
- super(P.class);
- }
-
- @Override
- public P deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
-
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("P");
- final JsonNode predicate = node.get("predicate");
- if (predicate.textValue().equals("and") || predicate.textValue().equals("or")) {
- final List<P<?>> arguments = new ArrayList<>();
- for (int i = 0; i < node.get("value").size(); i++) {
- arguments.add(oc.readValue(node.get("value").get(i).traverse(oc), P.class));
- }
- return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments);
- } else {
- try {
- final Object argument = oc.readValue(node.get("value").traverse(oc), Object.class);
- return (P) P.class.getMethod(predicate.textValue(), argument instanceof Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff, eh?
- } catch (final Exception e) {
- throw new IOException(e.getMessage(), e);
- }
- }
- }
- }
-
- final static class LambdaJacksonDeserializer extends StdDeserializer<Lambda> {
-
- public LambdaJacksonDeserializer() {
- super(Lambda.class);
- }
-
- @Override
- public Lambda deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
-
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Lambda");
- final String lambdaScript = node.get("value").textValue();
- final String lambdaLanguage = node.get("language").textValue();
- final int lambdaArguments = node.get("arguments").intValue();
- if (-1 == lambdaArguments || lambdaArguments > 2)
- return new Lambda.UnknownArgLambda(lambdaScript, lambdaLanguage, lambdaArguments);
- else if (0 == lambdaArguments)
- return new Lambda.ZeroArgLambda<>(lambdaScript, lambdaLanguage);
- else if (1 == lambdaArguments)
- return new Lambda.OneArgLambda<>(lambdaScript, lambdaLanguage);
- else
- return new Lambda.TwoArgLambda<>(lambdaScript, lambdaLanguage);
- }
- }
-
- final static class BindingJacksonDeserializer extends StdDeserializer<Bytecode.Binding> {
-
- public BindingJacksonDeserializer() {
- super(Bytecode.Binding.class);
- }
-
- @Override
- public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Binding");
- final String variable = node.get("variable").textValue();
- final Object value = oc.readValue(node.get("value").traverse(oc), Object.class);
- return new Bytecode.Binding<>(variable, value);
- }
- }
-
- static class TraverserJacksonDeserializer extends StdDeserializer<Traverser> {
-
- public TraverserJacksonDeserializer() {
- super(Traverser.class);
- }
-
- @Override
- public Traverser deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
- jsonParser.nextToken();
- // This will automatically parse all typed stuff.
- final Map<String, Object> mapData = deserializationContext.readValue(jsonParser, Map.class);
- return new DefaultRemoteTraverser<>(mapData.get("value"), (Long) mapData.get("bulk"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4eff70d6/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
new file mode 100644
index 0000000..6bad444
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@ -0,0 +1,424 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.structure.io.graphson;
+
+import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
+import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
+import org.apache.tinkerpop.shaded.jackson.core.JsonParser;
+import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
+import org.apache.tinkerpop.shaded.jackson.core.ObjectCodec;
+import org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext;
+import org.apache.tinkerpop.shaded.jackson.databind.JsonNode;
+import org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider;
+import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer;
+import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer;
+import org.apache.tinkerpop.shaded.jackson.databind.node.JsonNodeType;
+import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+final class GraphSONTraversalSerializersV2d0 {
+
+ private GraphSONTraversalSerializersV2d0() {
+ }
+
+ /////////////////
+ // SERIALIZERS //
+ ////////////////
+
+ final static class TraversalJacksonSerializer extends StdSerializer<Traversal> {
+
+ public TraversalJacksonSerializer() {
+ super(Traversal.class);
+ }
+
+ @Override
+ public void serialize(final Traversal traversal, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeObject(traversal.asAdmin().getBytecode());
+ }
+
+ }
+
+ final static class BytecodeJacksonSerializer extends StdSerializer<Bytecode> {
+
+ public BytecodeJacksonSerializer() {
+ super(Bytecode.class);
+ }
+
+ @Override
+ public void serialize(final Bytecode bytecode, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("@type", "Bytecode");
+ if (bytecode.getSourceInstructions().iterator().hasNext()) {
+ jsonGenerator.writeArrayFieldStart("source");
+ for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) {
+ jsonGenerator.writeStartArray();
+ jsonGenerator.writeString(instruction.getOperator());
+ for (final Object argument : instruction.getArguments()) {
+ jsonGenerator.writeObject(argument);
+ }
+ jsonGenerator.writeEndArray();
+ }
+ jsonGenerator.writeEndArray();
+ }
+ if (bytecode.getStepInstructions().iterator().hasNext()) {
+ jsonGenerator.writeArrayFieldStart("step");
+ for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) {
+ jsonGenerator.writeStartArray();
+ jsonGenerator.writeString(instruction.getOperator());
+ for (final Object argument : instruction.getArguments()) {
+ jsonGenerator.writeObject(argument);
+ }
+ jsonGenerator.writeEndArray();
+ }
+ jsonGenerator.writeEndArray();
+ }
+
+ jsonGenerator.writeEndObject();
+ }
+ }
+
+ final static class EnumJacksonSerializer extends StdSerializer<Enum> {
+
+ public EnumJacksonSerializer() {
+ super(Enum.class);
+ }
+
+ @Override
+ public void serialize(final Enum enumInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeObjectField("@type", enumInstance.getDeclaringClass().getSimpleName());
+ jsonGenerator.writeObjectField("value", enumInstance.name());
+ jsonGenerator.writeEndObject();
+ }
+
+ }
+
+ final static class PJacksonSerializer extends StdSerializer<P> {
+
+ public PJacksonSerializer() {
+ super(P.class);
+ }
+
+ @Override
+ public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("@type", "P");
+ jsonGenerator.writeStringField("predicate", p instanceof ConnectiveP ? p instanceof AndP ? "and" : "or" : p.getBiPredicate().toString());
+ jsonGenerator.writeObjectField("value", p instanceof ConnectiveP ? ((ConnectiveP) p).getPredicates() : p.getValue());
+ jsonGenerator.writeEndObject();
+ }
+
+ }
+
+ final static class LambdaJacksonSerializer extends StdSerializer<Lambda> {
+
+ public LambdaJacksonSerializer() {
+ super(Lambda.class);
+ }
+
+ @Override
+ public void serialize(final Lambda lambda, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("@type", "Lambda");
+ jsonGenerator.writeStringField("value", lambda.getLambdaScript());
+ jsonGenerator.writeStringField("language", lambda.getLambdaLanguage());
+ jsonGenerator.writeNumberField("arguments", lambda.getLambdaArguments());
+ jsonGenerator.writeEndObject();
+ }
+
+ }
+
+ final static class BindingJacksonSerializer extends StdSerializer<Bytecode.Binding> {
+
+ public BindingJacksonSerializer() {
+ super(Bytecode.Binding.class);
+ }
+
+ @Override
+ public void serialize(final Bytecode.Binding binding, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("@type", "Binding");
+ jsonGenerator.writeStringField("variable", binding.variable());
+ jsonGenerator.writeObjectField("value", binding.value());
+ jsonGenerator.writeEndObject();
+ }
+
+ }
+
+ final static class TraverserSerializer extends StdSerializer<Traverser> {
+
+ public TraverserSerializer() {
+ super(Traverser.class);
+ }
+
+ @Override
+ public void serialize(final Traverser traverserInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ ser(traverserInstance, jsonGenerator);
+ }
+
+ @Override
+ public void serializeWithType(final Traverser traverser, final JsonGenerator jsonGenerator,
+ final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
+ ser(traverser, jsonGenerator);
+ }
+
+ private void ser(final Traverser traverserInstance, final JsonGenerator jsonGenerator) throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("@type", "Traverser");
+ jsonGenerator.writeObjectField("bulk", traverserInstance.bulk());
+ jsonGenerator.writeObjectField("value", traverserInstance.get());
+ jsonGenerator.writeEndObject();
+ }
+ }
+
+ ///////////////////
+ // DESERIALIZERS //
+ //////////////////
+
+ final static class BytecodeJacksonDeserializer extends StdDeserializer<Bytecode> {
+
+ public BytecodeJacksonDeserializer() {
+ super(Bytecode.class);
+ }
+
+ private static void processInstruction(final JsonNode instruction, final ObjectCodec oc, final Bytecode bytecode, final boolean source) throws IOException {
+ final String operator = instruction.get(0).textValue();
+ final List<Object> arguments = new ArrayList<>();
+ for (int j = 1; j < instruction.size(); j++) {
+ final JsonNode argument = instruction.get(j);
+ if (argument.getNodeType().equals(JsonNodeType.OBJECT)) {
+ if (argument.has("@type")) {
+ final String type = argument.get("@type").textValue();
+ if (type.equals("Bytecode"))
+ arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class));
+ else if (type.equals("Binding"))
+ arguments.add(oc.readValue(argument.traverse(oc), Bytecode.Binding.class));
+ else if (type.equals("P"))
+ arguments.add(oc.readValue(argument.traverse(oc), P.class));
+ else if (type.equals("Lambda"))
+ arguments.add(oc.readValue(argument.traverse(oc), Lambda.class));
+ else
+ arguments.add(oc.readValue(argument.traverse(oc), Enum.class));
+ } else {
+ arguments.add(oc.readValue(argument.traverse(oc), Object.class)); // TODO: vertices/edges/etc. don't get processed correctly
+ }
+ } else if (argument.getNodeType().equals(JsonNodeType.NUMBER)) {
+ arguments.add(argument.asInt()); // TODO
+ } else if (argument.getNodeType().equals(JsonNodeType.STRING)) {
+ arguments.add(argument.textValue());
+ } else if (argument.getNodeType().equals(JsonNodeType.BOOLEAN)) {
+ arguments.add(argument.booleanValue());
+ } else if (argument.getNodeType().equals(JsonNodeType.ARRAY)) {
+ final List<Object> list = new ArrayList<>();
+ for (int k = 0; k < argument.size(); k++) {
+ list.add(oc.readValue(argument.get(k).traverse(oc), Object.class));
+ //list.add(argument.get(k).textValue());
+ }
+ arguments.add(list);
+ } else {
+ throw new IOException("Unknown argument: " + argument);
+ }
+ }
+ if (source)
+ bytecode.addSource(operator, arguments.toArray());
+ else
+ bytecode.addStep(operator, arguments.toArray());
+ }
+
+ @Override
+ public Bytecode deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ final Bytecode bytecode = new Bytecode();
+ final ObjectCodec oc = jsonParser.getCodec();
+ final JsonNode node = oc.readTree(jsonParser);
+ assert node.get("@type").textValue().equals("Bytecode");
+ if (node.has("source")) {
+ final JsonNode source = node.get("source");
+ for (int i = 0; i < source.size(); i++) {
+ processInstruction(source.get(i), oc, bytecode, true);
+ }
+ }
+ if (node.has("step")) {
+ final JsonNode step = node.get("step");
+ for (int i = 0; i < step.size(); i++) {
+ processInstruction(step.get(i), oc, bytecode, false);
+
+ }
+ }
+ return bytecode;
+ }
+ }
+
+ final static class EnumJacksonDeserializer extends StdDeserializer<Enum> {
+
+ public EnumJacksonDeserializer() {
+ super(Enum.class);
+ }
+
+ @Override
+ public Enum deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+
+ final ObjectCodec oc = jsonParser.getCodec();
+ final JsonNode node = oc.readTree(jsonParser);
+ final String type = node.get("@type").textValue();
+ if (type.equals("Cardinality"))
+ return VertexProperty.Cardinality.valueOf(node.get("value").textValue());
+ else if (type.equals("Column"))
+ return Column.valueOf(node.get("value").textValue());
+ else if (type.equals("Direction"))
+ return Direction.valueOf(node.get("value").textValue());
+ else if (type.equals("Barrier"))
+ return SackFunctions.Barrier.valueOf(node.get("value").textValue());
+ else if (type.equals("Operator"))
+ return Operator.valueOf(node.get("value").textValue());
+ else if (type.equals("Order"))
+ return Order.valueOf(node.get("value").textValue());
+ else if (type.equals("Pop"))
+ return Pop.valueOf(node.get("value").textValue());
+ else if (type.equals("Scope"))
+ return Scope.valueOf(node.get("value").textValue());
+ else if (type.equals("T"))
+ return T.valueOf(node.get("value").textValue());
+ else
+ throw new IOException("Unknown enum type: " + type);
+
+ }
+ }
+
+ final static class PJacksonDeserializer extends StdDeserializer<P> {
+
+ public PJacksonDeserializer() {
+ super(P.class);
+ }
+
+ @Override
+ public P deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+
+ final ObjectCodec oc = jsonParser.getCodec();
+ final JsonNode node = oc.readTree(jsonParser);
+ assert node.get("@type").textValue().equals("P");
+ final JsonNode predicate = node.get("predicate");
+ if (predicate.textValue().equals("and") || predicate.textValue().equals("or")) {
+ final List<P<?>> arguments = new ArrayList<>();
+ for (int i = 0; i < node.get("value").size(); i++) {
+ arguments.add(oc.readValue(node.get("value").get(i).traverse(oc), P.class));
+ }
+ return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments);
+ } else {
+ try {
+ final Object argument = oc.readValue(node.get("value").traverse(oc), Object.class);
+ return (P) P.class.getMethod(predicate.textValue(), argument instanceof Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff, eh?
+ } catch (final Exception e) {
+ throw new IOException(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ final static class LambdaJacksonDeserializer extends StdDeserializer<Lambda> {
+
+ public LambdaJacksonDeserializer() {
+ super(Lambda.class);
+ }
+
+ @Override
+ public Lambda deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+
+ final ObjectCodec oc = jsonParser.getCodec();
+ final JsonNode node = oc.readTree(jsonParser);
+ assert node.get("@type").textValue().equals("Lambda");
+ final String lambdaScript = node.get("value").textValue();
+ final String lambdaLanguage = node.get("language").textValue();
+ final int lambdaArguments = node.get("arguments").intValue();
+ if (-1 == lambdaArguments || lambdaArguments > 2)
+ return new Lambda.UnknownArgLambda(lambdaScript, lambdaLanguage, lambdaArguments);
+ else if (0 == lambdaArguments)
+ return new Lambda.ZeroArgLambda<>(lambdaScript, lambdaLanguage);
+ else if (1 == lambdaArguments)
+ return new Lambda.OneArgLambda<>(lambdaScript, lambdaLanguage);
+ else
+ return new Lambda.TwoArgLambda<>(lambdaScript, lambdaLanguage);
+ }
+ }
+
+ final static class BindingJacksonDeserializer extends StdDeserializer<Bytecode.Binding> {
+
+ public BindingJacksonDeserializer() {
+ super(Bytecode.Binding.class);
+ }
+
+ @Override
+ public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ final ObjectCodec oc = jsonParser.getCodec();
+ final JsonNode node = oc.readTree(jsonParser);
+ assert node.get("@type").textValue().equals("Binding");
+ final String variable = node.get("variable").textValue();
+ final Object value = oc.readValue(node.get("value").traverse(oc), Object.class);
+ return new Bytecode.Binding<>(variable, value);
+ }
+ }
+
+ static class TraverserJacksonDeserializer extends StdDeserializer<Traverser> {
+
+ public TraverserJacksonDeserializer() {
+ super(Traverser.class);
+ }
+
+ @Override
+ public Traverser deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ jsonParser.nextToken();
+ // This will automatically parse all typed stuff.
+ final Map<String, Object> mapData = deserializationContext.readValue(jsonParser, Map.class);
+ return new DefaultRemoteTraverser<>(mapData.get("value"), (Long) mapData.get("bulk"));
+ }
+ }
+}
[3/4] tinkerpop git commit: Made graphson types statically
initialized.
Posted by sp...@apache.org.
Made graphson types statically initialized.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d05e15cd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d05e15cd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d05e15cd
Branch: refs/heads/TINKERPOP-1278
Commit: d05e15cd3b84b6b1ca8dcd2ba864db18f28d9901
Parents: 5739326
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 06:43:34 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 06:43:34 2016 -0400
----------------------------------------------------------------------
.../structure/io/graphson/GraphSONModule.java | 75 ++++++++++----------
1 file changed, 39 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d05e15cd/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 3fe4a70..21a48f3 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
@@ -81,6 +81,44 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
* Version 2.0 of GraphSON.
*/
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");
+ }};
+
/**
* Constructs a new object.
*/
@@ -183,42 +221,7 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
@Override
public Map<Class, String> getTypeDefinitions() {
- return 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");
- }};
+ return TYPE_DEFINITIONS;
}
@Override
[2/4] tinkerpop git commit: Refactor and combine some graphson 2.0
tests.
Posted by sp...@apache.org.
Refactor and combine some graphson 2.0 tests.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5739326b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5739326b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5739326b
Branch: refs/heads/TINKERPOP-1278
Commit: 5739326b381e92da700ceda38e4cb24e37f2e59e
Parents: 4eff70d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 06:32:56 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 06:32:56 2016 -0400
----------------------------------------------------------------------
.../GraphSONTraversalSerializersV2d0.java | 67 +++++----
.../GraphSONMapperEmbeddedTypeTest.java | 3 +-
...hSONMapperV1d0ToV2d0BuilderSettingsTest.java | 86 -----------
...aphSONMapperV2d0PartialEmbeddedTypeTest.java | 144 ++++++-------------
4 files changed, 79 insertions(+), 221 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/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 6bad444..796e225 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
@@ -29,7 +29,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
@@ -92,7 +91,7 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Bytecode bytecode, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Bytecode");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Bytecode");
if (bytecode.getSourceInstructions().iterator().hasNext()) {
jsonGenerator.writeArrayFieldStart("source");
for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) {
@@ -132,8 +131,8 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Enum enumInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeObjectField("@type", enumInstance.getDeclaringClass().getSimpleName());
- jsonGenerator.writeObjectField("value", enumInstance.name());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUETYPE, enumInstance.getDeclaringClass().getSimpleName());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, enumInstance.name());
jsonGenerator.writeEndObject();
}
@@ -149,9 +148,9 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "P");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "P");
jsonGenerator.writeStringField("predicate", p instanceof ConnectiveP ? p instanceof AndP ? "and" : "or" : p.getBiPredicate().toString());
- jsonGenerator.writeObjectField("value", p instanceof ConnectiveP ? ((ConnectiveP) p).getPredicates() : p.getValue());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p instanceof ConnectiveP ? ((ConnectiveP) p).getPredicates() : p.getValue());
jsonGenerator.writeEndObject();
}
@@ -167,8 +166,8 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Lambda lambda, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Lambda");
- jsonGenerator.writeStringField("value", lambda.getLambdaScript());
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Lambda");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUE, lambda.getLambdaScript());
jsonGenerator.writeStringField("language", lambda.getLambdaLanguage());
jsonGenerator.writeNumberField("arguments", lambda.getLambdaArguments());
jsonGenerator.writeEndObject();
@@ -186,9 +185,9 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Bytecode.Binding binding, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Binding");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Binding");
jsonGenerator.writeStringField("variable", binding.variable());
- jsonGenerator.writeObjectField("value", binding.value());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, binding.value());
jsonGenerator.writeEndObject();
}
@@ -214,9 +213,9 @@ final class GraphSONTraversalSerializersV2d0 {
private void ser(final Traverser traverserInstance, final JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Traverser");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Traverser");
jsonGenerator.writeObjectField("bulk", traverserInstance.bulk());
- jsonGenerator.writeObjectField("value", traverserInstance.get());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, traverserInstance.get());
jsonGenerator.writeEndObject();
}
}
@@ -237,8 +236,8 @@ final class GraphSONTraversalSerializersV2d0 {
for (int j = 1; j < instruction.size(); j++) {
final JsonNode argument = instruction.get(j);
if (argument.getNodeType().equals(JsonNodeType.OBJECT)) {
- if (argument.has("@type")) {
- final String type = argument.get("@type").textValue();
+ if (argument.has(GraphSONTokens.VALUETYPE)) {
+ final String type = argument.get(GraphSONTokens.VALUETYPE).textValue();
if (type.equals("Bytecode"))
arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class));
else if (type.equals("Binding"))
@@ -280,7 +279,7 @@ final class GraphSONTraversalSerializersV2d0 {
final Bytecode bytecode = new Bytecode();
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Bytecode");
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Bytecode");
if (node.has("source")) {
final JsonNode source = node.get("source");
for (int i = 0; i < source.size(); i++) {
@@ -309,25 +308,25 @@ final class GraphSONTraversalSerializersV2d0 {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- final String type = node.get("@type").textValue();
+ final String type = node.get(GraphSONTokens.VALUETYPE).textValue();
if (type.equals("Cardinality"))
- return VertexProperty.Cardinality.valueOf(node.get("value").textValue());
+ return VertexProperty.Cardinality.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Column"))
- return Column.valueOf(node.get("value").textValue());
+ return Column.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Direction"))
- return Direction.valueOf(node.get("value").textValue());
+ return Direction.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Barrier"))
- return SackFunctions.Barrier.valueOf(node.get("value").textValue());
+ return SackFunctions.Barrier.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Operator"))
- return Operator.valueOf(node.get("value").textValue());
+ return Operator.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Order"))
- return Order.valueOf(node.get("value").textValue());
+ return Order.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Pop"))
- return Pop.valueOf(node.get("value").textValue());
+ return Pop.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Scope"))
- return Scope.valueOf(node.get("value").textValue());
+ return Scope.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("T"))
- return T.valueOf(node.get("value").textValue());
+ return T.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else
throw new IOException("Unknown enum type: " + type);
@@ -345,17 +344,17 @@ final class GraphSONTraversalSerializersV2d0 {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("P");
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("P");
final JsonNode predicate = node.get("predicate");
if (predicate.textValue().equals("and") || predicate.textValue().equals("or")) {
final List<P<?>> arguments = new ArrayList<>();
- for (int i = 0; i < node.get("value").size(); i++) {
- arguments.add(oc.readValue(node.get("value").get(i).traverse(oc), P.class));
+ for (int i = 0; i < node.get(GraphSONTokens.VALUE).size(); i++) {
+ arguments.add(oc.readValue(node.get(GraphSONTokens.VALUE).get(i).traverse(oc), P.class));
}
return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments);
} else {
try {
- final Object argument = oc.readValue(node.get("value").traverse(oc), Object.class);
+ final Object argument = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc), Object.class);
return (P) P.class.getMethod(predicate.textValue(), argument instanceof Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff, eh?
} catch (final Exception e) {
throw new IOException(e.getMessage(), e);
@@ -375,8 +374,8 @@ final class GraphSONTraversalSerializersV2d0 {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Lambda");
- final String lambdaScript = node.get("value").textValue();
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Lambda");
+ final String lambdaScript = node.get(GraphSONTokens.VALUE).textValue();
final String lambdaLanguage = node.get("language").textValue();
final int lambdaArguments = node.get("arguments").intValue();
if (-1 == lambdaArguments || lambdaArguments > 2)
@@ -400,9 +399,9 @@ final class GraphSONTraversalSerializersV2d0 {
public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Binding");
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Binding");
final String variable = node.get("variable").textValue();
- final Object value = oc.readValue(node.get("value").traverse(oc), Object.class);
+ final Object value = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc), Object.class);
return new Bytecode.Binding<>(variable, value);
}
}
@@ -418,7 +417,7 @@ final class GraphSONTraversalSerializersV2d0 {
jsonParser.nextToken();
// This will automatically parse all typed stuff.
final Map<String, Object> mapData = deserializationContext.readValue(jsonParser, Map.class);
- return new DefaultRemoteTraverser<>(mapData.get("value"), (Long) mapData.get("bulk"));
+ return new DefaultRemoteTraverser<>(mapData.get(GraphSONTokens.VALUE), (Long) mapData.get("bulk"));
}
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
index 7b197b6..6060a6d 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
@@ -53,8 +53,7 @@ public class GraphSONMapperEmbeddedTypeTest {
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{GraphSONMapper.build().version(GraphSONVersion.V1_0).embedTypes(true).create().createMapper()},
- {GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()
- .createMapper()},
+ {GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create().createMapper()},
});
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java
deleted file mode 100644
index 50600ee..0000000
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.io.graphson;
-
-import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.time.Duration;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.MonthDay;
-import java.time.OffsetDateTime;
-import java.time.OffsetTime;
-import java.time.Period;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class GraphSONMapperV1d0ToV2d0BuilderSettingsTest {
-
- @Test
- public void shouldHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
- final ObjectMapper mapper = GraphSONMapper.build()
- .version(GraphSONVersion.V1_0)
- .typeInfo(TypeInfo.PARTIAL_TYPES)
- .create()
- .createMapper();
-
- final Map<String,Object> m = new HashMap<>();
- m.put("test", 100L);
-
- final String json = mapper.writeValueAsString(m);
- final Map read = mapper.readValue(json, HashMap.class);
-
- assertEquals(100L, read.get("test"));
- }
-
- @Test
- public void shouldNotHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
- final ObjectMapper mapper = GraphSONMapper.build()
- .version(GraphSONVersion.V1_0)
- .typeInfo(TypeInfo.NO_TYPES)
- .create()
- .createMapper();
-
- final Map<String,Object> m = new HashMap<>();
- m.put("test", 100L);
-
- final String json = mapper.writeValueAsString(m);
- final Map read = mapper.readValue(json, HashMap.class);
-
- assertEquals(100, read.get("test"));
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
index c78505b..d1b7b52 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
@@ -27,17 +27,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.time.Duration;
import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.MonthDay;
-import java.time.OffsetDateTime;
-import java.time.OffsetTime;
-import java.time.Period;
-import java.time.Year;
-import java.time.YearMonth;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
@@ -65,94 +55,16 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
.createMapper();
@Test
- public void shouldHandleDurationAuto() throws Exception {
- final Duration o = Duration.ZERO;
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleInstantAuto() throws Exception {
- final Instant o = Instant.ofEpochMilli(System.currentTimeMillis());
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleLocalDateAuto() throws Exception {
- final LocalDate o = LocalDate.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleLocalDateTimeAuto() throws Exception {
- final LocalDateTime o = LocalDateTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleLocalTimeAuto() throws Exception {
- final LocalTime o = LocalTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleMonthDayAuto() throws Exception {
- final MonthDay o = MonthDay.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleOffsetDateTimeAuto() throws Exception {
- final OffsetDateTime o = OffsetDateTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleOffsetTimeAuto() throws Exception {
- final OffsetTime o = OffsetTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandlePeriodAuto() throws Exception {
- final Period o = Period.ofDays(3);
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleYearAuto() throws Exception {
- final Year o = Year.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleYearMonthAuto() throws Exception {
- final YearMonth o = YearMonth.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleZonedDateTimeAuto() throws Exception {
- final ZonedDateTime o = ZonedDateTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleZonedOffsetAuto() throws Exception {
- final ZoneOffset o = ZonedDateTime.now().getOffset();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- // Trying to fail the TypeDeserializer type detection
public void shouldSerializeDeserializeNestedCollectionsAndMapAndTypedValuesCorrectly() throws Exception {
+ // Trying to fail the TypeDeserializer type detection
final UUID uuid = UUID.randomUUID();
- final List myList = new ArrayList<>();
+ final List<Object> myList = new ArrayList<>();
- final List myList2 = new ArrayList<>();
+ final List<Object> myList2 = new ArrayList<>();
myList2.add(UUID.randomUUID());
myList2.add(33L);
myList2.add(84);
- final Map map2 = new HashMap<>();
+ final Map<String,Object> map2 = new HashMap<>();
map2.put("eheh", UUID.randomUUID());
map2.put("normal", "normal");
myList2.add(map2);
@@ -169,7 +81,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
// no "@value" property
String s = "{\""+GraphSONTokens.VALUETYPE+"\":\""+GraphSONTokens.GREMLIN_TYPE_NAMESPACE +":uuid\", \"test\":2}";
- Map map = new LinkedHashMap<>();
+ Map<String,Object> map = new LinkedHashMap<>();
map.put(GraphSONTokens.VALUETYPE, "gremlin:uuid");
map.put("test", 2);
Object res = mapper.readValue(s, Object.class);
@@ -232,7 +144,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
}
@Test
- public void shouldHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
+ public void shouldHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
final ObjectMapper mapper = GraphSONMapper.build()
.version(GraphSONVersion.V2_0)
.embedTypes(true)
@@ -249,7 +161,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
}
@Test
- public void shouldNotHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
+ public void shouldNotHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
final ObjectMapper mapper = GraphSONMapper.build()
.version(GraphSONVersion.V2_0)
.embedTypes(false)
@@ -266,6 +178,40 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
}
@Test
+ public void shouldHandleMapWithTypesUsingEmbedTypeSettingV1d0() throws Exception {
+ final ObjectMapper mapper = GraphSONMapper.build()
+ .version(GraphSONVersion.V1_0)
+ .typeInfo(TypeInfo.PARTIAL_TYPES)
+ .create()
+ .createMapper();
+
+ final Map<String,Object> m = new HashMap<>();
+ m.put("test", 100L);
+
+ final String json = mapper.writeValueAsString(m);
+ final Map read = mapper.readValue(json, HashMap.class);
+
+ assertEquals(100L, read.get("test"));
+ }
+
+ @Test
+ public void shouldNotHandleMapWithTypesUsingEmbedTypeSettingV1d0() throws Exception {
+ final ObjectMapper mapper = GraphSONMapper.build()
+ .version(GraphSONVersion.V1_0)
+ .typeInfo(TypeInfo.NO_TYPES)
+ .create()
+ .createMapper();
+
+ final Map<String,Object> m = new HashMap<>();
+ m.put("test", 100L);
+
+ final String json = mapper.writeValueAsString(m);
+ final Map read = mapper.readValue(json, HashMap.class);
+
+ assertEquals(100, read.get("test"));
+ }
+
+ @Test
public void shouldLooseTypesInfoWithGraphSONNoType() throws Exception {
final ObjectMapper mapper = GraphSONMapper.build()
.version(GraphSONVersion.V2_0)
@@ -274,13 +220,13 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
.createMapper();
final UUID uuid = UUID.randomUUID();
- final List myList = new ArrayList<>();
+ final List<Object> myList = new ArrayList<>();
- final List myList2 = new ArrayList<>();
+ final List<Object> myList2 = new ArrayList<>();
myList2.add(UUID.randomUUID());
myList2.add(33L);
myList2.add(84);
- final Map map2 = new HashMap<>();
+ final Map<String,Object> map2 = new HashMap<>();
map2.put("eheh", UUID.randomUUID());
map2.put("normal", "normal");
myList2.add(map2);
@@ -330,7 +276,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
public <T> T serializeDeserialize(final Object o, final Class<T> clazz) throws Exception {
try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
mapper.writeValue(stream, o);
-
+ final String s=mapper.writeValueAsString(o);
try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray())) {
return mapper.readValue(inputStream, clazz);
}
[4/4] tinkerpop git commit: Added a 'bulk' graphson token.
Posted by sp...@apache.org.
Added a 'bulk' graphson token.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/098b81f7
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/098b81f7
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/098b81f7
Branch: refs/heads/TINKERPOP-1278
Commit: 098b81f7803f8b197d7c40b1a41d9068e7276df9
Parents: d05e15c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 06:43:49 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 06:43:49 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/structure/io/graphson/GraphSONTokens.java | 2 ++
.../structure/io/graphson/GraphSONTraversalSerializersV2d0.java | 5 ++---
2 files changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/098b81f7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokens.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokens.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokens.java
index e24cbab..5171204 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokens.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokens.java
@@ -62,4 +62,6 @@ public final class GraphSONTokens {
public static final String NAME = "name";
public static final String COUNTS = "counts";
public static final String ANNOTATIONS = "annotations";
+
+ public static final String BULK = "Bulk";
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/098b81f7/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 796e225..88b6f63 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
@@ -213,8 +213,7 @@ final class GraphSONTraversalSerializersV2d0 {
private void ser(final Traverser traverserInstance, final JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Traverser");
- jsonGenerator.writeObjectField("bulk", traverserInstance.bulk());
+ jsonGenerator.writeObjectField(GraphSONTokens.BULK, traverserInstance.bulk());
jsonGenerator.writeObjectField(GraphSONTokens.VALUE, traverserInstance.get());
jsonGenerator.writeEndObject();
}
@@ -417,7 +416,7 @@ final class GraphSONTraversalSerializersV2d0 {
jsonParser.nextToken();
// This will automatically parse all typed stuff.
final Map<String, Object> mapData = deserializationContext.readValue(jsonParser, Map.class);
- return new DefaultRemoteTraverser<>(mapData.get(GraphSONTokens.VALUE), (Long) mapData.get("bulk"));
+ return new DefaultRemoteTraverser<>(mapData.get(GraphSONTokens.VALUE), (Long) mapData.get(GraphSONTokens.BULK));
}
}
}