Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
theigl opened this issue Feb 17, 2025 · 4 comments
Open
Labels
question Further information is requested

Comments

@theigl
Copy link
Contributor

theigl commented Feb 17, 2025

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 theigl added the question Further information is requested label Feb 17, 2025
@chaokunyang
Copy link
Collaborator

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));

@theigl
Copy link
Contributor Author

theigl commented Feb 17, 2025

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?

@chaokunyang
Copy link
Collaborator

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

@theigl
Copy link
Contributor Author

theigl commented Feb 17, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants