payamrastogi / kryo

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

com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 114 #148

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I get this exception when I try to serialize a class into a file, then add one 
new field to the class being serialized, and then trying to deserialize the 
same binary file with the updated version of the class.
I do understand that the old binary format is now incompatible with the new 
class, but I am handling serialization manually by implementing 
KryoSerializable interface for the class that is being serialized.

Here is my implementation of read() and write():

   @Override
    public void write(Kryo kryo, Output output) {
        output.writeLong(customVersion);
        kryo.writeClassAndObject(output,routingProperties);
        output.writeInt(batch.size());
        for(T item: batch){
            kryo.writeClassAndObject(output,item);
        }
        output.writeString(testNewField);
    }

    @Override
    public void read(Kryo kryo, Input input) {
        long version = input.readLong();
        if(version >= 1L){
            routingProperties = (Y) kryo.readClassAndObject(input);
            int batchSize = input.readInt();
            batch = new LinkedList<T>();
            for(int i=0;i<batchSize;i++){
                T item = (T) kryo.readClassAndObject(input);
                batch.add(item);
            }
        }
        if(version>=2L){
            //read in one additional field
            testNewField = input.readString();
        }
    }

What steps will reproduce the problem?

1. Serilalize a given class to a binary file
2. Add a new String field to a class being serialized
3. Try to deserialize the class from the old binary file but using the updated 
version of the class itself
4. Get an exception: com.esotericsoftware.kryo.KryoException: Encountered 
unregistered class ID: 114

What is the expected output? What do you see instead?

I thought that with my manual implementation for serialization, I should be 
able to deserialize the class even after I added testNewField to it.
Instead I see an exception.

What version of the Kryo are you using?
2.23

Please provide any additional information below.

Original issue reported on code.google.com by eugene...@gmail.com on 12 Feb 2014 at 8:47

GoogleCodeExporter commented 9 years ago
Show the exception and trace logs.

Original comment by n...@n4te.com on 12 Feb 2014 at 8:54

GoogleCodeExporter commented 9 years ago
But do it on github, no one uses this tracker anymore.

Original comment by n...@n4te.com on 12 Feb 2014 at 8:54

GoogleCodeExporter commented 9 years ago
Moved to GitHub https://github.com/EsotericSoftware/kryo/issues/194

Original comment by eugene...@gmail.com on 12 Feb 2014 at 9:21