-
Notifications
You must be signed in to change notification settings - Fork 829
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
Add a hook to intercept registration of all new serializers. #947
base: master
Are you sure you want to change the base?
Conversation
e5a2d16
to
ef968b5
Compare
Hi @chrisr3. Do you need this change for your custom serializer registration to work, or is this just something that would be nice to have? Would overriding |
Something like this would simplify my integration. The problem with overriding public Registration register (Class type, Serializer serializer) {
Registration registration = classResolver.getRegistration(type);
if (registration != null) {
registration.setSerializer(serializer);
return registration;
}
return classResolver.register(new Registration(type, serializer, getNextRegistrationId()));
} And not forgetting public Registration register (Class type) which invokes |
I mean something like this: public class MyClassResolver extends DefaultClassResolver {
@Override
public Registration register(Registration registration) {
return super.register(adapt(registration));
}
private Registration adapt(Registration registration) {
// modify registration here
return registration;
}
} WDYT? |
I think my customised And you presumably mean? protected Registration adapt(Registration registration) |
Do you have full control over the Kryo instance? Or can it be changed by clients/users? If you have full control, then using a custom class resolver isn't really an issue. It's just like any other configurable part of Kryo. |
We are already providing Kryo with a modified I've tried creating a protected Registration adapt(Registration) method, with the goal of adapting Kryo's invocations of |
I gave your issue more thought over the weekend: Even if I were to merge this change, you would still need a lot of complex code to achieve your desired behavior. Including your I see only one option that does not require you to write a lot of workarounds: Adding something like Again, this is most likely not a feature a lot of users are going to need. It adds to Kryo's public API and will have to be maintained in the future. On the other hand, it would be straightforward to implement and could even be made |
To be fair, I never intended to add my
Yes, I agree. This is why I was only trying to create a more general extension API that my adapter could use. |
I think we misunderstood each other slightly. ;) I understand that you don't plan to add your But I just gave this a quick try and I'm not happy with the solution. Even if I add a configuration flag, |
Regarding your PR: I'm not really happy about going from Kryo to DefaultClassResolver and then calling back into Kryo. And since these classes are in different packages, this means that the method in Kryo has to be public. Are you sure you can't simply override your class resolver directly? Or wrap it in a decorator that notifies your custom Kryo instance about new registrations? |
We're already turning the generics optimisation off because we're using Kotlin - see #864. Actually, I think I should dig deeper into that particular issue now... 🤔. |
Create a mechanism for customising, configuring, or even replacing a serializer when it is registered.
See #943.