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

gremlin-dotnet: GraphSONReader third-party type exposed

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.3.0
    • Fix Version/s: None
    • Component/s: dotnet
    • Labels:

      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

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

                Dates

                • Created:
                  Updated: