[ 
https://issues.apache.org/jira/browse/TINKERPOP-1696?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

stephen mallette updated TINKERPOP-1696:
----------------------------------------
    Component/s:     (was: language-variant)
                 dotnet

> gremlin-dotnet: GraphSONReader third-party type exposed
> -------------------------------------------------------
>
>                 Key: TINKERPOP-1696
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1696
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: dotnet
>    Affects Versions: 3.3.0
>            Reporter: Jorge Bay
>            Priority: Minor
>
> On gremlin-dotnet, the {{GraphSONReader}} public class and 
> {{IGraphSONDeserializer}} public interface uses {{JToken}} as a parameter, 
> which is a type defined in the third-party library Newtonsoft's Json.NET.
> {code:java}
> public class GraphSONReader {
>   public dynamic ToObject(JToken jToken) {
>     // ... implementation
>   }
> }
> {code}
> {code:java}
> public interface IGraphSONDeserializer {
>   object Objectify(JToken graphsonObject, GraphSONReader reader);
> }
> {code}
> Even though Json.NET is a well-known library, exposing a third-party library 
> type is usually not a good idea as it tightly couples both libraries, ie: 
> {{IGraphSONDeserializer}} implementers will have to use Json.NET.
> As we are dealing with JSON data, there is a benefit in parsing once and 
> access the parsed data, like its currently implemented (we should avoid using 
> strings and parse multiple times).
> I propose using 
> [{{dynamic}}|https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/using-type-dynamic]
>  instead. In C#, an object of type {{dynamic}} is basically a dictionary 
> without compile time checks, which is suitable for scenarios like this one.
> {code:java}
> public class GraphSONReader {
>   public dynamic ToObject(dynamic parsedJson) {
>     // ... implementation
>     string type = parsedJson["@type"];
>     // ... get the deserializer for the given type ...
>   }
> }
> {code}
> {code:java}
> public interface IGraphSONDeserializer {
>   object Objectify(dynamic graphsonObject, GraphSONReader reader);
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to