This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2235 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 5824b53dcc2aed18225da230096d9462cdd7bc0b Author: stephen <[email protected]> AuthorDate: Tue Nov 5 08:26:25 2019 -0500 TINKERPOP-2235 Fixed null handling in .NET --- .../src/Gremlin.Net/Process/Traversal/Bytecode.cs | 6 ++++++ .../Structure/IO/GraphSON/GraphSONWriter.cs | 18 +++++++++++------- .../Structure/IO/GraphSON/GraphSONReaderTests.cs | 4 ++-- .../Structure/IO/GraphSON/GraphSONWriterTests.cs | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Bytecode.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Bytecode.cs index e09c533..490e4e4 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Bytecode.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Bytecode.cs @@ -116,6 +116,12 @@ namespace Gremlin.Net.Process.Traversal if (variable != null) return new Binding(variable, ConvertArgument(argument, false)); } + + if (null == argument) + { + return null; + } + if (IsDictionaryType(argument.GetType())) { var dict = new Dictionary<object, object>(); 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 3268ae4..fc7765f 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs @@ -113,13 +113,17 @@ namespace Gremlin.Net.Structure.IO.GraphSON /// <returns>A GraphSON representation of the object ready to be serialized.</returns> public dynamic ToDict(dynamic objectData) { - var type = objectData.GetType(); - if (TryGetSerializerFor(out IGraphSONSerializer serializer, type)) - return serializer.Dictify(objectData, this); - if (IsDictionaryType(type)) - return DictToGraphSONDict(objectData); - if (IsCollectionType(type)) - return CollectionToGraphSONCollection(objectData); + if (objectData != null) + { + var type = objectData.GetType(); + if (TryGetSerializerFor(out IGraphSONSerializer serializer, type)) + return serializer.Dictify(objectData, this); + if (IsDictionaryType(type)) + return DictToGraphSONDict(objectData); + if (IsCollectionType(type)) + return CollectionToGraphSONCollection(objectData); + } + return objectData; } diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs index 3a49143..15bd5f9 100644 --- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs @@ -260,13 +260,13 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON [Theory, MemberData(nameof(Versions))] public void ShouldDeserializeList(int version) { - var serializedValue = "[{\"@type\":\"g:Int32\",\"@value\":5},{\"@type\":\"g:Int32\",\"@value\":6}]"; + var serializedValue = "[{\"@type\":\"g:Int32\",\"@value\":5},{\"@type\":\"g:Int32\",\"@value\":6},null]"; var reader = CreateStandardGraphSONReader(version); var jObject = JArray.Parse(serializedValue); var deserializedValue = reader.ToObject(jObject); - Assert.Equal(new List<object> {5, 6}, deserializedValue); + Assert.Equal(new List<object> {5, 6, null}, deserializedValue); } [Theory, MemberData(nameof(Versions))] diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs index 409776b..2eb7d51 100644 --- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs @@ -282,12 +282,12 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON public void ShouldSerializeGList(int version) { var writer = CreateGraphSONWriter(version); - var list = new List<object> {5, 6}; + var list = new List<object> {5, 6, null}; var serializedGraphSON = writer.WriteObject(list); var expectedGraphSON = "{\"@type\":\"g:List\",\"@value\":[{\"@type\":\"g:Int32\",\"@value\":5}," + - "{\"@type\":\"g:Int32\",\"@value\":6}]}"; + "{\"@type\":\"g:Int32\",\"@value\":6},null]}"; Assert.Equal(expectedGraphSON, serializedGraphSON); }
