Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-1696

gremlin-dotnet: GraphSONReader third-party type exposed

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.3.0
    • None
    • dotnet

    Description

      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.

      public class GraphSONReader {
        public dynamic ToObject(JToken jToken) {
          // ... implementation
        }
      }
      
      public interface IGraphSONDeserializer {
        object Objectify(JToken graphsonObject, GraphSONReader reader);
      }
      

      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 instead. In C#, an object of type dynamic is basically a dictionary without compile time checks, which is suitable for scenarios like this one.

      public class GraphSONReader {
        public dynamic ToObject(dynamic parsedJson) {
          // ... implementation
          string type = parsedJson["@type"];
          // ... get the deserializer for the given type ...
        }
      }
      
      public interface IGraphSONDeserializer {
        object Objectify(dynamic graphsonObject, GraphSONReader reader);
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jorgebg Jorge Bay
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: