Serializing JsonNode

30 views
Skip to first unread message

Jeff

unread,
Mar 31, 2023, 6:25:37 AM3/31/23
to Gremlin-users
Hi folks, 

I've a gremlin server (JanusGraph) and am trying to add a vertex to a graph in Java code but am facing some serialization errors which I can't understand.

The server serializers are configured like below

serializers:
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, config: { serializeResultToString: true }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}

The code to connect and add a vertex is 

var registry =
      TypeSerializerRegistry.build().addRegistry(JanusGraphIoRegistry.instance()).create();
    var cluster = Cluster.build("localhost").port(8182)
        .serializer(new GraphBinaryMessageSerializerV1(registry)).create();

var json = mapper.valueToTree(obj);
g.addV(LABEL).property(PROPERTY, json).next();

The error i see is

io.netty.handler.codec.EncoderException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An error occurred during serialization of this request [REQUEST MESSAGE REDACTED] - it could not be sent to the server - Reason: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.io.IOException: Serializer for type org.apache.tinkerpop.shaded.jackson.databind.node.ObjectNode not found
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:104) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1071) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An error occurred during serialization of this request [REQUEST MESSAGE REDACTED] - it could not be sent to the server - Reason: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.io.IOException: Serializer for type org.apache.tinkerpop.shaded.jackson.databind.node.ObjectNode not found
at org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:60) ~[gremlin-driver-3.5.5.jar:3.5.5]
at org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:38) ~[gremlin-driver-3.5.5.jar:3.5.5]
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89) ~[netty-all-4.1.66.Final.jar:4.1.66.Final]
... 9 common frames omitted

Both server and driver are already using the same serializers and https://docs.janusgraph.org/advanced-topics/serializer/ states that it should be able to deserialize ObjectNodes, so what could be the cause of this? Even using a normal byte[] will fail in code but when the same is done thru the gremlin-console, it does seem to work.

My issue could be worked around by using a JSON string instead of a JSON node but i really want to understand what went wrong or did i misunderstand how serializers work in the system.

Apologies if this is not the right channel but I've asked over at stackoverflow with no answers.

Stephen Mallette

unread,
Apr 1, 2023, 10:43:59 AM4/1/23
to gremli...@googlegroups.com
A JsonNode is not a supported type for GraphBinary:


GraphBinary also doesn't do Array exactly which is why i assume byte[] didn't work - it would have to be List<Byte> i guess or a ByteBuffer in Java.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/6926adaa-60a6-41ad-994a-b7c09a46af87n%40googlegroups.com.

Jeff

unread,
Apr 3, 2023, 2:15:03 AM4/3/23
to Gremlin-users
Got it! Thanks Stephen!
Reply all
Reply to author
Forward
0 new messages