twitter / chill

Scala extensions for the Kryo serialization library
https://twitter.com/scalding
Apache License 2.0
609 stars 156 forks source link

How can deserialize a data #311

Open rimeh-bennjima opened 6 years ago

rimeh-bennjima commented 6 years ago

I use Kryo-sharded-4.0.1 I want to deserialize a data but I have an Exception when I write: kryo.fromBytes(bytes)

com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException: Index: 32, Size: 12 at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731) at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731) at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731) at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813) at com.twitter.chill.SerDeState.readClassAndObject(SerDeState.java:61) at com.twitter.chill.KryoPool.fromBytes(KryoPool.java:94)

johnynek commented 6 years ago

How was the data written? Looks like the data is not correct. Can you show a full failing example using KryoPool.toBytes()?

rimeh-bennjima commented 6 years ago

@johnynek An example of Data: case class User(id: Int, cin: Int, details: UserDetails)

case class UserDetails(name: String, login: String, password: String, creationTime: LocalDateTime)

kryoPool.toBytesWithClass(User)

johnynek commented 6 years ago

User is the companion object not any instance of the class, not that it should matter.

LocalDateTime May give you a problem depending on how you set up the kryoPool.

Can you send a PR with a failing test so I can see the whole runnable example?