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/23 08:16:22 UTC
[47/50] 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/ad78f6eb
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/ad78f6eb
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/ad78f6eb
Branch: refs/heads/TINKERPOP-1827
Commit: ad78f6eb45c786077ddfb26db3b844be6b0fcd4f
Parents: 176d5d2
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 23 09:08:08 2017 +0100
----------------------------------------------------------------------
.../Process/Traversal/DefaultTraversal.cs | 11 +++++--
.../Structure/IO/GraphSON/DecimalConverter.cs | 34 ++++++++++++++++++++
.../Structure/IO/GraphSON/GraphSONReader.cs | 15 +++++++--
.../Structure/IO/GraphSON/GraphSONWriter.cs | 1 +
.../Structure/IO/GraphSON/NumberConverter.cs | 3 +-
5 files changed, 58 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ad78f6eb/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/DefaultTraversal.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/DefaultTraversal.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/DefaultTraversal.cs
index 7e0f37b..052c33a 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/DefaultTraversal.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/DefaultTraversal.cs
@@ -91,9 +91,16 @@ namespace Gremlin.Net.Process.Traversal
}
/// <inheritdoc />
- public E Current => (E)TraverserEnumerator.Current?.Object;
+ public E Current => (E) GetCurrent();
- object IEnumerator.Current => Current;
+ /// <inheritdoc />
+ object IEnumerator.Current => GetCurrent();
+
+ private object GetCurrent()
+ {
+ // Use the object (not dynamic) result
+ return TraverserEnumerator.Current?.Object;
+ }
private IEnumerator<Traverser> GetTraverserEnumerator()
{
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ad78f6eb/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/ad78f6eb/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/ad78f6eb/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/ad78f6eb/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