[ 
https://issues.apache.org/jira/browse/TINKERPOP-2067?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16682377#comment-16682377
 ] 

ASF GitHub Bot commented on TINKERPOP-2067:
-------------------------------------------

FlorianHockmann closed pull request #972: TINKERPOP-2067 Allow getting raw 
JToken data from Gremlin.Net.Driver.GremlinClient.
URL: https://github.com/apache/tinkerpop/pull/972
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs 
b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
index b79f0e620f..23d76c6f5a 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -100,7 +100,10 @@ private async Task<IReadOnlyCollection<T>> 
ReceiveAsync<T>()
                 }
                 else if (status.Code != ResponseStatusCode.NoContent)
                 {
-                    var receivedData = 
_graphSONReader.ToObject(receivedMsg.Result.Data);
+                    var receivedData = typeof(T) == typeof(JToken)
+                        ? new[] { receivedMsg.Result.Data }
+                        : _graphSONReader.ToObject(receivedMsg.Result.Data);
+
                     foreach (var d in receivedData)
                         if 
(receivedMsg.Result.Meta.ContainsKey(Tokens.ArgsSideEffectKey))
                         {
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
index 9a421d59b3..56ebfc3fa8 100644
--- 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
+++ 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
@@ -29,6 +29,7 @@
 using Gremlin.Net.Driver.Exceptions;
 using Gremlin.Net.Driver.Messages;
 using Gremlin.Net.IntegrationTest.Util;
+using Newtonsoft.Json.Linq;
 using Xunit;
 
 namespace Gremlin.Net.IntegrationTest.Driver
@@ -68,6 +69,34 @@ public async Task ShouldHandleBigResponse()
             }
         }
 
+        [Fact]
+        public async Task 
ShouldReturnResultWithoutDeserializingItForJTokenType()
+        {
+            var gremlinServer = new GremlinServer(TestHost, TestPort);
+            using (var gremlinClient = new GremlinClient(gremlinServer))
+            {
+                var gremlinScript = "'someString'";
+                
+                var response = await 
gremlinClient.SubmitWithSingleResultAsync<JToken>(gremlinScript);
+
+                //Expected:
+                /* {
+                  "@type": "g:List",
+                  "@value": [
+                    "someString"
+                  ]
+                }*/
+
+                Assert.IsType<JObject>(response);
+                Assert.Equal("g:List", response["@type"]);
+
+                var jArray = response["@value"] as JArray;
+                Assert.NotNull(jArray);
+                Assert.Equal(1, jArray.Count);
+                Assert.Equal("someString", (jArray[0] as JValue)?.Value);
+            }
+        }
+
         [Fact]
         public async Task ShouldHandleResponseWithoutContent()
         {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Allow getting raw data from Gremlin.Net.Driver.IGremlinClient
> -------------------------------------------------------------
>
>                 Key: TINKERPOP-2067
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2067
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: dotnet
>    Affects Versions: 3.3.3
>            Reporter: Daniel C. Weber
>            Priority: Minor
>
> I am developing an ORM-style [server driver for 
> Gremlin|https://github.com/ExRam/ExRam.Gremlinq]. To communicate with 
> Gremlin-servers, I rely on 
> [Gremlin.net|https://github.com/ExRam/ExRam.Gremlinq/tree/master/ExRam.Gremlinq.Providers.WebSocket].
> Since ExRam.Gremlinq deals with deserializing Json data to POCOs by itself, 
> it needs to get raw data from an IGremlinClient. Currently, it's only safe to 
> use SubmitAsync<T> with object or dynamic as T, or other (scalar) types if 
> known it advance. To get a raw JToken, I currently use a 
> [hack|https://github.com/ExRam/ExRam.Gremlinq/blob/master/ExRam.Gremlinq.Providers.WebSocket/GremlinClientQueryProvider.cs#L34].
> The hack is not only ugly, it prohibits users of ExRam.Gremlinq to create and 
> pass in instances of IGremlinClient by themselves, which could become 
> necessary e.g. for adjusting the Graphson version etc.
> I had a look into the sources of Gremlin.net. It deserializes a server's 
> answer to a ResponseMessage<JToken>, so the JToken is available in any case. 
> It would be a trivial change to check the type parameter T and return the 
> token if typeof(T) == typeof(JToken), and I could definitely file the PR for 
> that. However, I'm of course less aware of possible unintended implications. 
> Any thoughts are appreciated!
>  
> thx
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to