You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deserialization fails with "Unable to read unknown data" after removing a field with Collection type from the class (Issue with backward compatibility)
#907
Open
Malobika8 opened this issue
Aug 16, 2022
· 1 comment
Got KryoException: ClassNotFoundException(with Maps) /Encountered unregistered class ID(with Lists)
when I try to deserialize data after removing a field with Collection type from the class.
To Reproduce
With Map:
First, serialize the original object.
publicstaticclassTestClass {
Stringvalue;
Map<Integer, String> map; //Comment during deserialization
}
@Testpublicvoidtest_deserialize() {
finalFileclassSerialized =
newFile(TEST_RESOURCES_PATH + "/serializedObj.exj");
//This reads from the serialized file and internally calls [readObject (Input input, Class<T> type)](https://github.com/EsotericSoftware/kryo/blob/master/src/com/esotericsoftware/kryo/Kryo.java#L765)TestClasstestClass = readObject(classSerialized, serializer);
assertNotNull(testClass);
assertEquals("some string", testClass.value);
}
Got
com.esotericsoftware.kryo.kryo5.KryoException: Unable to read unknown data, type: java.util.LinkedHashMap (TestClass#null)
at com.esotericsoftware.kryo.kryo5.serializers.CompatibleFieldSerializer.read(CompatibleFieldSerializer.java:153)
at com.esotericsoftware.kryo.kryo5.serializers.CompatibleFieldSerializer.read(CompatibleFieldSerializer.java:153)
... 75 more
Caused by: java.lang.ClassNotFoundException: ��\ at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
With List:
First, serialize the original object.
publicstaticclassTestClass {
Stringvalue;
List<Long> id; //Comment during deserialization
}
publicstaticvoidserialize() throwsIOException {
StringsomeString = "some string";
List<Long> id = newArrayList<>();
list.add(1111L);
list.add(2222L);
TestClasstestClass = newTestClass();
testClass.value = someString;
testClass.id = id;
finalFileclassSerialized =
newFile(TEST_RESOURCES_PATH + "/serializedObj.exj");
//This internally calls [writeObject(Output output, Object object)](https://github.com/EsotericSoftware/kryo/blob/master/src/com/esotericsoftware/kryo/Kryo.java#L620) and puts serialized data in a filewriteObject(testClass, classSerialized, serializer);
}
Then, comment field id, and run
@Testpublicvoidtest_deserialize() {
finalFileclassSerialized =
newFile(TEST_RESOURCES_PATH + "/serializedObj.exj");
//This reads from the serialized file and internally calls [readObject (Input input, Class<T> type)](https://github.com/EsotericSoftware/kryo/blob/master/src/com/esotericsoftware/kryo/Kryo.java#L765)TestClasstestClass = readObject(classSerialized, serializer);
assertNotNull(testClass);
assertEquals("some string", testClass.value);
}
Got
com.esotericsoftware.kryo.kryo5.KryoException: Unable to read unknown data, type: java.util.ArrayList (TestClass#null)
... 70 more
Caused by: com.esotericsoftware.kryo.kryo5.KryoException: Encountered unregistered class ID: 2466
Additional context
When we try out the same with Kryo version 2.24.0, it works fine and deserializes properly. However, the same fails with Kryo version 5.3.0.
I learned that the problem can be solved with config.setChunkedEncoding(true);
However, I noticed it doesn't throw any error even with non-passive changes like changing data type of a field. We want to avoid that.
Is there any other thing that can be done to solve the problem? Thank you in advance!
The text was updated successfully, but these errors were encountered:
A similar problem was described in #834. I debugged the issue at the time, but was unable to come up with a solution.
I'd recommend that you use chunked encoding. Alternatively, you can debug the problem and create a PR if you find a solution/workaround. Unfortunately, I don't have the capacity to spend time on this issue in the near future.
Got KryoException: ClassNotFoundException(with Maps) /Encountered unregistered class ID(with Lists)
when I try to deserialize data after removing a field with Collection type from the class.
To Reproduce
With Map:
First, serialize the original object.
Then, comment field map, and run
Got
With List:
First, serialize the original object.
Then, comment field id, and run
Got
Additional context
When we try out the same with Kryo version 2.24.0, it works fine and deserializes properly. However, the same fails with Kryo version 5.3.0.
FYI, the config looks like this -
I learned that the problem can be solved with config.setChunkedEncoding(true);
However, I noticed it doesn't throw any error even with non-passive changes like changing data type of a field. We want to avoid that.
Is there any other thing that can be done to solve the problem? Thank you in advance!
The text was updated successfully, but these errors were encountered: