Skip to content

Conversation

@mattjubb
Copy link

@mattjubb mattjubb commented Oct 5, 2025

Why?

In my project we have 1000s of classes that are serialized, we have a custom mechanism for registering those class using a UUID which provides a way to lookup those classes at runtime. It would be useful to be able to hook up this mechanism to the fory serializer. This is my first time trying to contribute to open source project so appreciate any guidance

What does this PR do?

This PR adds a new interface ClassInfoSerializer which can be implemented to specify a custom way to serialize a class ID instead of the default short id. this can be set on the ClassResolver via setClassInfoSerializer

Does this PR introduce any user-facing change?

Yes introduces new interface - ClassInfoSerializer and ClassResolver.setClassInfoSerializer method

-->

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change? - yes if custom class info serializer is set, otherwise no

Benchmark

not performed yet

@mattjubb mattjubb requested a review from chaokunyang as a code owner October 5, 2025 01:31
* default implementation uses a short value, however when the class registration needs to be customized
* this can be set of the ClassResolver to handle storing the ClassInfo is a customized manner
*/
public interface ClassInfoSerializer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will introduce another indirection, and incur virtual method call. The performance will degrade. Could you share some detais what will you implement using this ClassInfoSerializer. Maybe we could just merge the funtions of subclass of ClassInfoSerializer into class resolver

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PR description and the unit test show examples of how this would be used. Basically we maintain a large mapping of identifiers to classes, when an object is deserialized we want to control what ID is mapped to what class. I asked about this on slack a couple months ago, and you said that we cannot customize the class resolve since it final and you suggest instead to raise a PR that supports customized mapping logic. the intent of this feature is for it to be customizable by the calling code not something that is predefined within the class resolver

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fory support register class by name. How about register class by uuid as name? Would this work for you? Your extension is in critical path. We are trying to keep callstack on this be as simple as we can. And you intercept whole class info serialization. Your class schema can't change anymore. The type forward/backward compatibility is implementes in current write/read classinfo method.

Copy link
Author

@mattjubb mattjubb Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would require registering all classes upfront which means loading the .class, for large amounts of classes that is a very large upfront cost, lets say we have 10,000 classes and we only want to deserialize a single object with a single class - that would mean loading all 10,000 .class to just serialize a single object. if we could provide a fully qualified name (fqn) which could then be loaded when required via Class.forName then registering by name would probably meet our needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants