-
Notifications
You must be signed in to change notification settings - Fork 826
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 make a library with custom serializers #778
Comments
Also: What should I do to make it compatible with both Kryo 4.x and 5.x? Or is that simply not possible? |
The only change in Kryo 5 is that the default value for
What exactly do you mean? Do you simply want to write tests against Kryo 4 and Kryo 5 or do you want to include production code that references Kryo? If you only want to write tests that make sure that your classes can be serialized with Kryo 4 and 5, you can include Kryo 4 as you did before and depend on the the versioned artifact for Kryo 5: |
If you want to find all classes that need to be registered for your test case, set the following flags and check the logs:
I hope that helps. |
What I mean with the Kryo 4.x/5.x is that my library is used in applications written by other people. |
But on your side this simply means that you write two test-cases. One for Kryo 4 and one for Kryo 5. Correct? Or do you include some kind of |
Yes, for some of my classes I need custom code to ensure the transient elements are initialized correctly upon arrival. |
So I run my test with the "setWarnUnregisteredClasses" you indicated and I found two things:
which says
From what I now understand this seems to be sliding into a situation where every library (even the Java runtime) gets a "registerClassesWithKryo(Kryo kryo)" method. Seems a bit much for a serialization system especially because it seems optional to register. |
Thank you for the feedback Niels!
Good catch. I'll push an improvement shortly.
As I said before: For your use-case (i.e. replacement of Java serialization for object graphs with a large number of classes), I'd recommend that you simply turn off |
Thanks for taking the time to explain. This really helps. So the However a class in a separate library I use is a Java 9+ module and is not exported at all and not accessible in a similar way as what you can do with EmptySet. I simply cannot reach this class at all as it is only used in an internal datastructure. So that makes an 'end-user' project essentially one of these two scenarios:
Now since the Java 11 JRE is modular and does not expose all classes and does not have a My unfortunate conclusion right now is that the new default setting in 5.x regarding the |
See #398 for why the default value was changed. |
Thanks for your explanations. |
#778 Use canonical class name for registration hint if available
@theigl A quick headsup on how I solved my problem. I have written a few libraries and I want to support downstream applications for the scenario's I have made this possible by essentially making Kryo optional, both in dependencies and code. To make sure the serialization actually works for the downstream projects as I want it; I added several maven sub modules with different dependencies to ensure I can test if everything works as expected in all cases https://github.com/nielsbasjes/prefixmap/tree/master/serialization Note that this code is still a bit new and raw and I'm looking into cleaning it. |
Hi,
I have written this library that is used in various places in other projects: https://github.com/nielsbasjes/yauaa
Now to make it all efficient I have made sure it is all serializable with both the standard Java serialization and Kryo.
This is also needed to support systems like Apache Flink and Apache Beam.
With Kryo 5.0.0 a change has been introduced that essentially requires registering the classes with the Kryo instance OR indicate this is not needed (i.e. optional registration). ( See also question #770 )
To make the registration of all needed classes as easy as possible I started by creating a method that returns the list of classes that need to be registered.
I stopped this effort when I got this error from my test:
So my question is what is the correct/best way of doing this for my library so that it will work 'nicely' for the applications that include my library?
The text was updated successfully, but these errors were encountered: