fury icon indicating copy to clipboard operation
fury copied to clipboard

[Question] How to force codegen serializer for custom JDK serialization?

Open theigl opened this issue 10 months ago • 4 comments

Question

Hi,

Fury shows the following (correct) warning for one of my classes:

class xy.SimplePrincipalCollection customized jdk serialization, which is inefficient. Please replace it with a org.apache.fury.serializer.Serializer or implements java.io.Externalizable.

I have no control over this class and cannot write an efficient custom serializer because internals cannot be accessed without reflection. How can I force Fury to use the default JIT/Codegen serializer for this class?

theigl avatar Feb 17 '25 15:02 theigl

If you force Fury to use the default JIT/Codegen serializer, the writeObject/readObject method in SimplePrincipalCollection won't be invoked, which may be unexpected if users did some special action in those methods.

If you do want to enfore fury serialization, you can do it by:

fury.registerSerializer(SimplePrincipalCollection.class, org.apache.fury.serializer.CodegenSerializer#loadCodegenSerializer(SimplePrincipalCollection.class));

chaokunyang avatar Feb 17 '25 16:02 chaokunyang

If you force Fury to use the default JIT/Codegen serializer, the writeObject/readObject method in SimplePrincipalCollection won't be invoked, which may be unexpected if users did some special action in those methods.

That makes sense. In this case I reviewed the custom JDK serialization and it is perfectly fine to use JIT instead.

Unfortunately, your suggested solution does not work for me. The first argument to loadCodegenSerializer is a Fury instance, but I only have access to a ThreadSafeFury.

fury.registerSerializer(SimplePrincipalCollection.class, 
    CodegenSerializer.loadCodegenSerializer(fury, SimplePrincipalCollection.class));

Is there another way?

theigl avatar Feb 17 '25 16:02 theigl

org.apache.fury.AbstractThreadSafeFury#registerCallback can be used

chaokunyang avatar Feb 17 '25 16:02 chaokunyang

Ok thanks! I will use this for now, but it requires casting and the method itself is marked as internal. It would be great to have a prettier option to force Fury to ignore JDK serialization for a class.

theigl avatar Feb 17 '25 16:02 theigl