Avi-Levi / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

CompatibleFieldSerializer read/writes field schema only once #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
Create 2 simple objects:
ObjectB: boolean field
ObjectA: ObjectB field
2.
Create an instance of ObjectA and set a instance of ObjectB
3.
Serialize ObjectA using a CompatibleFieldSerializer as default serializer
4.
Try to deserialize the byte array

What is the expected output? What do you see instead?
Expected a deserialized object graph containing ObjectA that has a reference to 
a instance of ObjectB but the output is a ClassCastException when deserializing 
the ObjectB instance.

Debugging shows the following:
When serializing the object (starting with ObjectA) it will write a schema to 
the output containing the field names, it will also set a key: 'schemaWritten' 
in the ObjectMap. When serializing ObjectB it checks for the 'schemaWritten' 
key, which is already set so it will not write a schema.

When deserializing it wil try reading a schema, its starts with ObjectA so it 
wil read its field names and set them in the ObjectMap under the 'schema' key. 
When deserializing ObjectB it wil check for the 'schema' key in the ObjectMap, 
the key exists so it re-uses the schema... So while reading the object data it 
wil try to set a field that is part of ObjectA in an instance of ObjectB 
resulting in a ClassCastException.

Possible fix: creating a ObjectMap instance for every object type the 
serializer encounters, this ensures that a schema is written/read once for 
every object type. Currently there is 1 shared instance of the ObjectMap.

What version of the Kryo are you using?
2.05

Please provide any additional information below.
Attached is a test-case (extension on CompatibleFieldSerializerTest)

Original issue reported on code.google.com by dries.sc...@gmail.com on 20 Apr 2012 at 6:56

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the detailed report and test. I will be traveling until Tuesday, 
then I will look at fixing this and possibly improving 
CompatibleFieldSerializer.

Original comment by nathan.s...@gmail.com on 20 Apr 2012 at 7:17

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r218.

Original comment by nathan.s...@gmail.com on 26 Apr 2012 at 1:33

GoogleCodeExporter commented 9 years ago
Fixed by using the serializer as the context key. Thanks!

Original comment by nathan.s...@gmail.com on 26 Apr 2012 at 1:34