0

I get the following error when trying to serialize a SimpleDirectedGraph:

com.esotericsoftware.kryo.KryoException: java.lang.IllegalArgumentException: Unable to create serializer "com.esotericsoftware.kryo.serializers.FieldSerializer" for class: org.jgrapht.graph.SimpleDirectedGraph

My internet search regarding this type of error returns a lot of people recommending the user update to the ASM 4.0 library. I am using Kryo 2.2 All, which includes the ASM 4.0 library. I also tried including the ASM 4 library on its own just in case, but no luck.

I have tried serializing simpler objects such as ArrayList. Those go fine. I am not clear why kryo is failing to serialize this graph class. Does anyone have an idea?

Update: Since I am working with a graph, I have tried implementing the experimental "continuations" branch of kryo https://github.com/EsotericSoftware/kryo/issues/103

Unfortunately, I still receive the same error.

Update: I think the trick might be using a different kind of serializer. Unfortunately, I can't seem to find one that will work with a SimpleDirectedGraph. BeanSerializer only serializes the first object layer. Nested objects don't seem to get serialized. The other serializers just throw the same error as FieldSerializer. Is there a serializer that folks normally use with graphs?

melchoir55
  • 6,842
  • 7
  • 60
  • 106

1 Answers1

0

My solution to this is not ideal. Hopefully someone else can post with a better one. The way I got through this was to specify the java serialization for just the SimpleDirectedGraph object.

    kryo.addDefaultSerializer(SimpleDirectedGraph.class, JavaSerializer.class);

This solution lets you still make use of Kryo serializers for other classes because it only applies the inefficient java serialization to a class which, in my case, was not the majority of the structure of the object.

The ideal solution would be to employ a Kryo serializer which works with a SimpleDirectedGraph. I was unable to find one.

melchoir55
  • 6,842
  • 7
  • 60
  • 106