-
Notifications
You must be signed in to change notification settings - Fork 829
Migration to v5
Kryo v5 brings many improvements that are incompatible with previous versions. This page highlights some of the most commonly encountered differences. If you come up with information that would be helpful to have here, please don't hesitate to help improve this page.
Serializer read
has changed. The old method:
T read (Kryo kryo, Input input, Class<T> type)
The new method:
T read (Kryo kryo, Input input, Class<? extends T> type)
Using the old method signature results in an ugly error:
Name clash: The method read(Kryo, Input, Class<T>) of type SomeSerializer has the same erasure as read(Kryo, Input, Class<? extends T>) of type Serializer<T> but does not override it
- Registration is now required by default (#398).
Any Kryo upgrade is a big event with a lot of potential for breakage. Moving from v2 to v5 or from v4 to v5 is about the same: the newer Kryo version is unlikely to be able to read bytes written with the older version. If going through the pain to update, moving to the latest makes the most sense. Also consider that if an older version is working fine, it may not be worth the pain to update.
The best approach is to load the old data somehow, then write it with the newer version. For example, by juggling classloaders the data could be loaded with v2, then written with v5. This is best because it is unreasonable to attempt to modify the old data to make it acceptable for the newer Kryo version.
The same can be done by moving the old data to an intermediary format. For example, load the data with Kryo v2 and write it to JSON. Update your application to Kryo v5, load the JSON data to objects, then write it with v5. The end result is the same as before, but without using classloaders and with the extra trouble of writing and reading the data to another format. Libraries like JsonBeans can do that automatically, at least for relatively simple object graphs.
If you allow your users to bring v2 data into your latest app which uses a new Kryo, you'll have to keep your classes compatible with the old v2 data. One way around this is to keep a snapshot of the old classes which your application no longer uses, then write code to convert old objects to your newer classes.