I check the source code of Kryo, it seems that when registering a class, it uses auto increment ID for it, if this is the case, what will happen if the writer and reader use different registeration order,
# writer
kryo.register(Foo.class);
kryo.register(Bar.class);
# reader
kryo.register(Bar.class);
kryo.register(Foo.class);
Will the deserialization still work? If not, wouldn't this be a problem? Because there's a pretty high possibility that writer and reader are not in the same application, therefore no easy way to ensure both register classes in the same order, right? Or am I missing something here?
If we use the automatically generated IDs then deserialization won't work if the order of registrations is different. It is mentioned in Kryo's documentation .
There is an option to pass an integer ID while registering the class. This way, we don't have to worry about the order.
You can also make those IDs a static final member of the class.