I would like to be able to use scala pickling in order to store binary representation of a case class.
I would like to know if there is a way to manage versioning of case class (the way protocol buffer allows to do)
Here is my example
I make a program at a certain date, with the following case class
case class MessageTest(a:String,b:String)
Then I serialize an instance of this class
import scala.pickling._
import binary._
val bytes=MessageTest("1","2").pickle
And then I store the result into a file
Later on, I might now have to make evolution on my case class, to add a new optional field
case class MessageTest (a:String,b:String,c:Option[String]=None)
I would like to be able to reuse the data that I stored previously in my file , to deserialize it and be able to recover an instance of a case class (with default value for the new parameter)
But when I use the following code
import scala.pickling._
import binary._
val messageback=bytes.unpickle[MessageTest]
I got the following error :
java.lang.ArrayIndexOutOfBoundsException: 26 at scala.pickling.binary.BinaryPickleReader$$anonfun$2.apply(BinaryPickleFormat.scala:446) at scala.pickling.binary.BinaryPickleReader$$anonfun$2.apply(BinaryPickleFormat.scala:434) at scala.pickling.PickleTools$class.withHints(Tools.scala:498) at scala.pickling.binary.BinaryPickleReader.withHints(BinaryPickleFormat.scala:425) at scala.pickling.binary.BinaryPickleReader.beginEntryNoTagDebug(BinaryPickleFormat.scala:434) at scala.pickling.binary.BinaryPickleReader.beginEntryNoTag(BinaryPickleFormat.scala:431)
Did I do something wrong ?
Is there an existing way to make my scenario work ?
Regards