not cross compatible scala 2.12.13 with scala 2.11.12
DimaGolomozy opened this issue · 6 comments
bytes that were serialized in scala 2.11.12 are not deserialzed in scala 2.12.13
specially a nested class with option field.
in scala 2.11.12:
case class A(s: String, b: B)
case class B(s: String, option: Option[String])
val object = A("test", B("test", Some("option")))
val kryoSerializer = ...
val scala211Bytes = kryoSerializer.toBInary(object)
now print the bytes and use them in a variable:
in scala 2.12.13:
// the bytes from val scala211Bytes
val bytesFromScala211 = Array[Byte](1,0,99,111,109,46,115,101,99,102,117,108,46,103,97,116,101,119,97,121,99,111,110,116,114,111,108,108,101,114,46,-63,1,2,-126,98,-126,115,76,1,1,99,111,109,46,115,101,99,102,117,108,46,103,97,116,101,119,97,121,99,111,110,116,114,111,108,108,101,114,46,-62,1,2,111,112,116,105,111,-18,-126,115,25,1,2,115,99,97,108,97,46,83,111,109,-27,1,1,-126,120,7,1,111,112,116,105,111,-18,0,0,5,1,116,101,115,-12,0,0,1,6,0)
val kryoSerializer = ...
kryoSerialzer.fromBInary(bytesFromScala211). <-- throws exception
Exception:
java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
Serialization trace:
s (com.secful.gatewaycontroller.A)
com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
Serialization trace:
s (com.secful.gatewaycontroller.A)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144)
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.read(CompatibleFieldSerializer.java:110)
at com.secful.common.akka.serialization.OptionAwareCompatibleFieldSerializer.read(OptionAwareCompatibleFieldSerializer.scala:12)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)
at io.altoo.akka.serialization.kryo.KryoSerializerBackend.fromBinary(KryoSerializerBackend.scala:42)
at io.altoo.akka.serialization.kryo.KryoSerializer.fromBinary(KryoSerializer.scala:188)
at akka.serialization.Serializer.fromBinary(Serializer.scala:66)
at akka.serialization.Serializer.fromBinary$(Serializer.scala:66)
at io.altoo.akka.serialization.kryo.KryoSerializer.fromBinary(KryoSerializer.scala:72)
Hi,
Kryo does high performance binary serialization. As there is no binary compatibility guaranteed between minor Scala versions this is bound to fail.
For such use cases a serializer with an independent serialization format like JSON would be more suitable.
cool.. thats for the quick response..
strange that it happens only for "nested Option".. like all other types work :\
Which version do you use? 2.0.0 used Kryo 5.0.0 which had generic optimizations enabled but had a bug that manifested itself in the same way (nested Option).
ohhh.. we use kryo-shaded 3.0.3
so you might be in the wrong project and be looking for https://github.com/EsotericSoftware/kryo?
ill have a look.. thanks for the help
closing this one