You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2017/11/30 09:20:13 UTC

[29/33] tinkerpop git commit: Decimal serialization support and avoid dynamic conversion

Decimal serialization support and avoid dynamic conversion


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

Branch: refs/heads/TINKERPOP-1827
Commit: 5d15f2e420fe769066c97ae2a1dc3771a80320f1
Parents: aab0e5c
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Tue Nov 21 11:39:38 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Thu Nov 30 10:01:18 2017 +0100

----------------------------------------------------------------------
 .../Structure/IO/GraphSON/DecimalConverter.cs   | 34 ++++++++++++++++++++
 .../Structure/IO/GraphSON/GraphSONReader.cs     | 15 +++++++--
 .../Structure/IO/GraphSON/GraphSONWriter.cs     |  1 +
 .../Structure/IO/GraphSON/NumberConverter.cs    |  3 +-
 4 files changed, 49 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5d15f2e4/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
new file mode 100644
index 0000000..82cc646
--- /dev/null
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
@@ -0,0 +1,34 @@
+#region License
+
+/*
+ * 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.
+ */
+
+#endregion
+
+using System;
+
+namespace Gremlin.Net.Structure.IO.GraphSON
+{
+    internal class DecimalConverter : NumberConverter
+    {
+        protected override string GraphSONTypeName => "BigDecimal";
+        protected override Type HandledType => typeof(decimal);
+        protected override string Prefix => "gx";
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5d15f2e4/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
index aa1fc48..60bafed 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
@@ -48,7 +48,8 @@ namespace Gremlin.Net.Structure.IO.GraphSON
                 {"g:Edge", new EdgeDeserializer()},
                 {"g:Property", new PropertyDeserializer()},
                 {"g:VertexProperty", new VertexPropertyDeserializer()},
-                {"g:Path", new PathDeserializer()}
+                {"g:Path", new PathDeserializer()},
+                {"gx:BigDecimal", new DecimalConverter()}
             };
 
         /// <summary>
@@ -89,9 +90,17 @@ namespace Gremlin.Net.Structure.IO.GraphSON
         public dynamic ToObject(JToken jToken)
         {
             if (jToken is JArray)
+            {
                 return jToken.Select(t => ToObject(t));
-            if (!jToken.HasValues) return ((JValue) jToken).Value;
-            if (!HasTypeKey(jToken)) return ReadDictionary(jToken);
+            }
+            if (jToken is JValue jValue)
+            {
+                return jValue.Value;
+            }
+            if (!HasTypeKey(jToken))
+            {
+                return ReadDictionary(jToken);
+            }
             return ReadTypedValue(jToken);
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5d15f2e4/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
index 3c17d14..ab7e7d0 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
@@ -49,6 +49,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON
                 {typeof(long), new Int64Converter()},
                 {typeof(float), new FloatConverter()},
                 {typeof(double), new DoubleConverter()},
+                {typeof(decimal), new DecimalConverter()},
                 {typeof(Guid), new UuidSerializer()},
                 {typeof(DateTime), new DateSerializer()},
                 {typeof(Type), new ClassSerializer()},

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5d15f2e4/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
index 579d202..294db12 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
@@ -31,6 +31,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON
     {
         protected abstract string GraphSONTypeName { get; }
         protected abstract Type HandledType { get; }
+        protected virtual string Prefix => "g";
 
         public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
         {
@@ -39,7 +40,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON
 
         public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
         {
-            return GraphSONUtil.ToTypedValue(GraphSONTypeName, objectData);
+            return GraphSONUtil.ToTypedValue(GraphSONTypeName, objectData, Prefix);
         }
     }
 }
\ No newline at end of file