0

I have problem with instanceof in java. For clarification, I use aws-neptune-jdbc drive for connection to janusgraph server.

I create GraphSONMessageSerializerV3d0 which is obviously instance of MessageSerializer. After that i put serializer in Properties. And even in properties this object in instance of MessageSerializer.

Code for this part:

GraphSONMapper.Builder builder = GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());
GraphSONMessageSerializerV3d0 serializer = new GraphSONMessageSerializerV3d0(builder);
System.out.println(String.format("Serializer: %s", serializer));
System.out.println(String.format("Name of serializer class: %s", serializer.getClass().getName()));
System.out.println(String.format("Serializer is instance of MessageSerializer: %s", serializer instanceof MessageSerializer));
properties.put("serializer", serializer);
System.out.println(String.format("Serializer in properties: %s", properties.get("serializer")));
System.out.println(String.format("Serializer in properties is instance of MessageSerializer: %s", properties.get("serializer") instanceof MessageSerializer));

And output for this part:

Serializer: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0@4d49af10
Name of serializer class: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
Serializer is instance of MessageSerializer: true
Serializer in properties: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0@4d49af10
Serializer in properties is instance of MessageSerializer: true

But in driver, I add some info in log, I can see, that something, that is in map under key serializer, is not a MessageSerializer and GraphSONMessageSerializerV3d0, but has class name GraphSONMessageSerializerV3d0

My code with logger in jdbc for this part

LOGGER.info(String.format("Creating cluster with serializer: %s", properties.get(GremlinConnectionProperties.SERIALIZER_KEY)));
LOGGER.info(String.format("Serializer is null?: %s", properties.get(GremlinConnectionProperties.SERIALIZER_KEY) == null));
LOGGER.info(String.format("Class of serializer is: %s", properties.get(GremlinConnectionProperties.SERIALIZER_KEY).getClass().getName()));
LOGGER.info(String.format("Serializer is GraphSONMessageSerializerV3d0?: %s", properties.get(GremlinConnectionProperties.SERIALIZER_KEY) instanceof GraphSONMessageSerializerV3d0));
LOGGER.info(String.format("Serializer is MessageSerializer?: %s", properties.get(GremlinConnectionProperties.SERIALIZER_KEY) instanceof MessageSerializer));

And output for this part

378 [main] INFO software.aws.neptune.gremlin.GremlinQueryExecutor - Creating cluster with serializer: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0@4d49af10
379 [main] INFO software.aws.neptune.gremlin.GremlinQueryExecutor - Serializer is null?: false
379 [main] INFO software.aws.neptune.gremlin.GremlinQueryExecutor - Class of serializer is: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
380 [main] INFO software.aws.neptune.gremlin.GremlinQueryExecutor - Serializer is GraphSONMessageSerializerV3d0?: false
380 [main] INFO software.aws.neptune.gremlin.GremlinQueryExecutor - Serializer is MessageSerializer?: false

Why is that? I need it to be true. I have same version of gremlin-driver in my script and aws-neptune-jdbc, which is 3.5.3. In github aws-neptune-jdbc right now have gremlin version 3.4.8, but I change it for myself.

P.S. Forgot to mention, my version of java is openjdk version "1.8.0_342"

1 Answers1

0

I found out what was the problem. aws-neptune-jdbc-driver has in build.gradle this line, when you gather everything in signle jar file.

relocate 'org.apache.tinkerpop', 'shadow.org.apache.tinkerpop'

Because of it, MessageSerializer in driver is shadow.org.apache.tinkerpop.gremlin.driver.MessageSerializer, and MessageSerializer in my script is just org.apache.tinkerpop.gremlin.driver.MessageSerializer and this is indeed different classes. If I understand correctly, only fix for this is juts remove this line from build.gradle?