-
Notifications
You must be signed in to change notification settings - Fork 826
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
CompatibleFieldSerializerFactory sometimes doesn't work while add new object as field #643
Comments
What version of Kryo are you using? With v5 (
|
I take it back, I do see an issue when |
Trace logs for writing:
For reading:
The problem is when writing, the I'm afraid there's not much that can be done. The only way to make it safe us if you don't use references. You could disable references for String.class (override As a last resort, you could likely write your own serializer which stores ID -> reference mappings separate from the serialized data. Kryo writes the reference IDs, so you may want to modify Kryo to not do that. The IDs themselves are available from the ReferenceResolver. FWIW, I prefer using TaggedFieldSerializer. It is efficient and backward compatible, but not forward compatible. |
I have a class in server side and client side. And the class is like this:
In the newer version, there are some changes, and the new structure is like this.
While a value appears twice or above, an IndexOutOfBoundsException is thrown.
Here is my test test code, both the code are tested in a same class, here I separate encode from decode.
Encode:
Decode:
I view the source code and learn that it is caused by references,
Stirng`` Hello Kryo!
appears 3 times, in the first time it is stored intoMapReferenceResolver.writeObjects
, and the next two store the index of the firstHello Kryo!
. While read the Input, SomeClass doesn't have fieldanotherClass
and the ClassAnotherClass
doesn't exist in the older version, the firstHello Kryo!
can not be read intoMapReferenceResolver.readObjects
, so the next twoHello Kryo!
will fail while read by references.I also learned that the problem can be solved with
kryo.setReferences(false);
, but it may affect performance and circular references may exist in my project.Is there any other thing I can do to solve the problem? Thank you in advance!
The text was updated successfully, but these errors were encountered: