[jira] [Commented] (TINKERPOP-2094) Gremlin Driver Cluster Builder serializer method does not use mimeType as suggested

2018-11-20 Thread Lyndon Armitage (JIRA)


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

Lyndon Armitage commented on TINKERPOP-2094:


Thanks for the quick response Stephen!

That is a better solution than changing the code :) 
I hadn't thought about the fact that application/json could correspond several 
different versions  of GraphSON.

Slightly unrelated, but may help others (and future me) if this gets indexed by 
a search engine; the context I mentioned about struggling to understand 
something was me mistakenly trying to serialize a whole graph (or subgraph) 
from a traversal, something that seems to only be supported on a local 
TinkerGraph implementation. You end up with some nice error messages saying 
stuff like:
{noformat}
unregistered class ID: 65536{noformat}
which is what eventually led me to tinker with the serializers thinking I had 
messed up my configuration. I was trying to do this so I could add some 
debugging code to an application and lazily wanted to be able to get a graph 
using the subgraph step, have it come over the wire, then use the GraphML 
Writer to output it.

> 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)


[jira] [Created] (TINKERPOP-2094) Gremlin Driver Cluster Builder serializer method does not use mimeType as suggested

2018-11-16 Thread Lyndon Armitage (JIRA)
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)