magro / kryo-serializers

More kryo serializers
Apache License 2.0
381 stars 120 forks source link

Add fastutil serializers #76

Open shevek opened 7 years ago

shevek commented 7 years ago

I should test to figure out whether this is actually required or not. If fastutil serializes by default, then this ticket was a waste of your time.

https://github.com/apache/giraph/blob/4f9c6c24a8b4b03e2836c77fe2e53e38b6519420/giraph-core/src/main/java/org/apache/giraph/writable/kryo/serializers/FastUtilSerializer.java

interesting strategy, but works.

magro commented 7 years ago

Looking forward to the results of your test ;-)

shevek commented 7 years ago

snerk nicely played. I'll get there.

robertvazan commented 3 years ago

Vanilla kryo 5.1.1 selects MapSerializer for fastutil's Object2IntOpenHashMap (fastutil 8.5.2), which fails with this exception:

com.esotericsoftware.kryo.KryoException: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
Serialization trace:
testField (com.test.Test)
    at com.esotericsoftware.kryo.serializers.ReflectField.write(ReflectField.java:101)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:107)
    at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:711)
    at ...
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:140)
    at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:42)
    at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:642)
    at com.esotericsoftware.kryo.serializers.ReflectField.write(ReflectField.java:70)

Serialized class contains:

private final Object2IntMap<String> testField;
public Test(String someParam) {
    testField = new Object2IntOpenHashMap<String>();
    // fill in some data
}

I guess fastutil needs custom serializer that takes precedence over default collection serializers.

How is everyone dealing with this? Are people adding the entire Apache Giraph core as a dependency? Or is everyone adding an override for all fastutil classes/interfaces that forces use of FieldSerializer JavaSerializer?

BTW, is this project alive? There have been no commits for 2 years.

robertvazan commented 3 years ago

My current workaround is this:

kryo.addDefaultSerializer(Object2IntMap.class, new JavaSerializer();

This has to be done for every top-level interface in fastutil. This could be added to kryo-serializers.

robertvazan commented 3 years ago

I could do a quick pull request copying Giraph code if there is someone around to merge it.