Vertex and Edge serialization
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e95b8eab Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e95b8eab Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e95b8eab Branch: refs/heads/tp32 Commit: e95b8eabc2f7fdb7dd943d18905141e2e7746aa0 Parents: b9ca2ca Author: Jorge Bay Gondra <jorgebaygon...@gmail.com> Authored: Tue Nov 28 12:50:37 2017 +0100 Committer: Jorge Bay Gondra <jorgebaygon...@gmail.com> Committed: Fri Jan 19 09:30:16 2018 +0100 ---------------------------------------------------------------------- .../lib/structure/io/graph-serializer.js | 42 ++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e95b8eab/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js index 46d251e..ff3d72d 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js @@ -65,7 +65,9 @@ var serializers = [ TraverserSerializer, PSerializer, LambdaSerializer, - EnumSerializer + EnumSerializer, + VertexSerializer, + EdgeSerializer ]; /** @@ -237,7 +239,7 @@ BytecodeSerializer.prototype._serializeInstructions = function (instructions) { } var result = new Array(instructions.length); result[0] = instructions[0]; - for (var i = 1; i < instructions.length; i++) { + for (var i = 0; i < instructions.length; i++) { result[i] = this.writer.adaptObject(instructions[i]); } return result; @@ -258,7 +260,7 @@ PSerializer.prototype.serialize = function (item) { var resultValue = result[valueKey] = { 'predicate': item.operator }; - if (item.other == undefined) { + if (item.other === undefined || item.other === null) { resultValue['value'] = this.writer.adaptObject(item.value); } else { @@ -340,6 +342,21 @@ VertexSerializer.prototype.deserialize = function (obj) { return new g.Vertex(this.reader.read(value['id']), value['label'], this.reader.read(value['properties'])); }; +/** @param {Vertex} item */ +VertexSerializer.prototype.serialize = function (item) { + var result = {}; + result[typeKey] = 'g:Vertex'; + result[valueKey] = { + 'id': this.writer.adaptObject(item.id), + 'label': item.label + }; + return result; +}; + +VertexSerializer.prototype.canBeUsedFor = function (value) { + return (value instanceof g.Vertex); +}; + function VertexPropertySerializer() { } @@ -380,6 +397,25 @@ EdgeSerializer.prototype.deserialize = function (obj) { ); }; +/** @param {Edge} item */ +EdgeSerializer.prototype.serialize = function (item) { + var result = {}; + result[typeKey] = 'g:Edge'; + result[valueKey] = { + 'id': this.writer.adaptObject(item.id), + 'label': item.label, + 'outV': this.writer.adaptObject(item.outV.id), + 'outVLabel': item.outV.label, + 'inV': this.writer.adaptObject(item.inV.id), + 'inVLabel': item.inV.label + }; + return result; +}; + +EdgeSerializer.prototype.canBeUsedFor = function (value) { + return (value instanceof g.Edge); +}; + function PathSerializer() { }