Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kryo Deserialization fails with "KryoException: Buffer underflow"

I use Kryo to write Objects into byte arrays. It works fine. But when the byte arrays are converted into the Objects, it throws, com.esotericsoftware.kryo.KryoException: Buffer underflow. exception.

This is my deserialization:

        Kryo k=new Kryo();
        Input input=new Input(byteArrayOfObject);           
        Object o=k.readObject(input,ObjectClass.class);

Furthermore, always the object type cannot be defined in my application. At the final process, the class conversion happens. Therefore,

  • How can I solve above deserialization error

  • Is there a way to create Object without giving the class into readObject(...,ClassName) ?

like image 322
Débora Avatar asked Jun 30 '14 06:06

Débora


1 Answers

This happened to me when I was not correctly closing the Output / Input types. You need to make sure Kryo flushes everything but doing output.flush() or output.close().

Second, look into kryo.writeClassAndObject(). You can then do kryo.readClassAndObject() and cast your object to the type it is supposed to be.

like image 60
sydraz Avatar answered Sep 19 '22 19:09

sydraz