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

stephen mallette closed TINKERPOP-2094.
---------------------------------------
       Resolution: Fixed
         Assignee: stephen mallette
    Fix Version/s: 3.3.5
                   3.4.0

thanks for mentioning this inconsistency. i changed the javadoc a bit to have 
it reflect how this should have been working:

https://github.com/apache/tinkerpop/commit/6de41bffb9aa7d50288f5d2211a9bdd7940716d9

I think that there was a time when it did work they way the javadoc described 
it but when multiple versions of the different serializers became available and 
the mimetypes ended up not having specific serializers (e.g. by 3.3.0, 
"application/json" could have been GraphSON 1.0 with no types of GraphSON 3.0) 
the implementation was changed to force a specific serializer selection. I 
guess we (i) missed updating the javadoc. 

> 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
>            Assignee: stephen mallette
>            Priority: Minor
>             Fix For: 3.4.0, 3.3.5
>
>
> 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)

Reply via email to