tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [36/50] tinkerpop git commit: Added Date GraphSON serialization for Javascript CTR
Date Thu, 26 Jul 2018 17:23:43 GMT
Added Date GraphSON serialization for Javascript CTR


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

Branch: refs/heads/TINKERPOP-1913
Commit: db46c0f67fb1f93b9ea76032dbd2a852c24effd4
Parents: f56a3e7
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Jul 25 09:45:30 2018 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Jul 25 09:45:30 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                |  1 +
 .../lib/structure/io/graph-serializer.js          |  2 ++
 .../lib/structure/io/type-serializers.js          | 18 ++++++++++++++++++
 .../gremlin-javascript/test/unit/graphson-test.js |  8 ++++++++
 4 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db46c0f6/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f076ba1..0f2b18b 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -24,6 +24,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 === TinkerPop 3.2.10 (Release Date: NOT OFFICIALLY RELEASED YET)
 
 * Match numbers in `choose()` options using `NumberHelper` (match values, ignore data type).
+* Added support for GraphSON serialization of `Date` in Javascript.
 * Fixed bug in Java driver where an disorderly shutdown of the server would cause the client
to hang.
 * Added a dotnet template project that should make it easier to get started with Gremlin.Net.
 * Removed `ThreadInterruptCustomizerProvider` from documentation as a way to timeout.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db46c0f6/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 df05659..55b0265 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
@@ -155,6 +155,7 @@ const deserializers = {
   'g:Int64':  typeSerializers.NumberSerializer,
   'g:Float':  typeSerializers.NumberSerializer,
   'g:Double': typeSerializers.NumberSerializer,
+  'g:Date': typeSerializers.DateSerializer,
   'g:Vertex': typeSerializers.VertexSerializer,
   'g:Edge': typeSerializers.EdgeSerializer,
   'g:VertexProperty': typeSerializers.VertexPropertySerializer,
@@ -165,6 +166,7 @@ const deserializers = {
 
 const serializers = [
   typeSerializers.NumberSerializer,
+  typeSerializers.DateSerializer,
   typeSerializers.BytecodeSerializer,
   typeSerializers.TraverserSerializer,
   typeSerializers.PSerializer,

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db46c0f6/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
index 304888f..4bc2935 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
@@ -61,6 +61,23 @@ class NumberSerializer extends TypeSerializer {
   }
 }
 
+class DateSerializer extends TypeSerializer {
+  serialize(item) {
+    return {
+      [typeKey]: 'g:Date',
+      [valueKey]: item.value.getTime()
+    };
+  }
+
+  deserialize(obj) {
+    return new Date(obj[valueKey]);
+  }
+
+  canBeUsedFor(value) {
+    return (value instanceof Date);
+  }
+}
+
 class LongSerializer extends TypeSerializer {
   serialize(item) {
     return {
@@ -278,6 +295,7 @@ class TSerializer extends TypeSerializer {
 
 module.exports = {
   BytecodeSerializer,
+  DateSerializer,
   EdgeSerializer,
   EnumSerializer,
   LambdaSerializer,

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db46c0f6/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
index 8bc7571..8f749f7 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
@@ -46,6 +46,14 @@ describe('GraphSONReader', function () {
       assert.strictEqual(result, item[1]);
     });
   });
+  it('should parse Date', function() {
+    const obj = { "@type" : "g:Date", "@value" : 1481750076295 };
+    const reader = new GraphSONReader();
+    const result = reader.read(obj);
+    console.log("++++++++++++++++++++++++++" + obj);
+    console.log("++++++++++++++++++++++++++" + result);
+    assert.ok(result instanceof Date);
+  });
   it('should parse vertices from GraphSON', function () {
     const obj = {
       "@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person",


Mime
View raw message