Lyndon Armitage created TINKERPOP-2094: ------------------------------------------
Summary: Gremlin Driver Cluster Builder serializer method does not use mimeType as suggested Key: TINKERPOP-2094 URL: https://issues.apache.org/jira/browse/TINKERPOP-2094 Project: TinkerPop Issue Type: Bug Components: driver Affects Versions: 3.3.4 Environment: Linux Java 8 Kotlin Reporter: Lyndon Armitage 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: {code:java} /** * 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; } {code} 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: {code:java} public Builder serializer(final String mimeType) { for (Serializers serializer : Serializers.values()) { if (serializer.getValue().equals(mimeType)) { this.serializer = serializer.simpleInstance(); break; } } return this; } {code} 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. -- This message was sent by Atlassian JIRA (v7.6.3#76005)