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

Gremlin Driver Cluster Builder serializer method does not use mimeType as suggested

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.3.4
    • 3.4.0, 3.3.5
    • driver
    • None
    • Linux
      Java 8
      Kotlin

    Description

      Whilst struggling with getting serialization working as expected during testing I noticed that the following method does not work as expected:

      org.apache.tinkerpop.gremlin.driver.Cluster.Builder#serializer(java.lang.String)

      Specifically this code:

      /**
       * Set the {@link MessageSerializer} to use given its MIME type.  Note that setting this value this way
       * will not allow specific configuration of the serializer itself.  If specific configuration is required
       * please use {@link #serializer(MessageSerializer)}.
       */
      public Builder serializer(final String mimeType) {
          serializer = Serializers.valueOf(mimeType).simpleInstance();
          return this;
      }
      

      It suggests that the string argument being used should be a MIME type like "application/json" but due to how the method Serializers.valueOf() works it in fact checks the enum name value.

      See the class org.apache.tinkerpop.gremlin.driver.ser.Serializers for some context.

      The valueOf method checks against the name of the enum which for the "appliction/json" example would actually be "GRAPHSON".

      There is a property called value and function called getValue() that were probably the intended targets for matching against.

      A solution for this would be to simply check against each enum instance's value property via the getter method mentioned earlier. Something like this:

      public Builder serializer(final String mimeType) {
          for (Serializers serializer : Serializers.values()) {
              if (serializer.getValue().equals(mimeType)) {
                  this.serializer = serializer.simpleInstance();
                  break;
              }
          }
          return this;
      }
      

      You could extract this (or the matching part of it) into a static method on the Serializers enum type if such a matching pattern is common. 

      Attachments

        Activity

          People

            spmallette Stephen Mallette
            larmitage Lyndon Armitage
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: