Cannot pickle Array but can pickle List in Scala with Pickling

286 views Asked by At

I wrote this method:

    def serialize(obj: Array[Track], file: File) {
    val pickle = obj.pickle;
    println(pickle.toString());
    val writer = new PrintWriter(file);
    writer.write(pickle.toString());
    writer.flush();
}

which gives me this error:

Exception in thread "main" java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:165)
at scala.pickling.ReactMap.insertIfNotThere(ReactMap.scala:55)
at scala.pickling.internal.package$.lookupPicklee(package.scala:106)
at BillboardsHot100$TrackPickler1$2$.pickle(Billboards.scala:46)
at BillboardsHot100$TrackPickler1$2$.pickle(Billboards.scala:46)
at scala.pickling.LowPriorityPicklersUnpicklers$$anon$1$$anonfun$pickle$1$$anonfun$apply$1.apply(Custom.scala:109)
at scala.pickling.LowPriorityPicklersUnpicklers$$anon$1$$anonfun$pickle$1$$anonfun$apply$1.apply(Custom.scala:107)
at scala.pickling.json.JSONPickleBuilder.putElement(JSONPickleFormat.scala:145)
at scala.pickling.LowPriorityPicklersUnpicklers$$anon$1$$anonfun$pickle$1.apply(Custom.scala:107)
at scala.pickling.LowPriorityPicklersUnpicklers$$anon$1$$anonfun$pickle$1.apply(Custom.scala:106)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:34)
at scala.pickling.LowPriorityPicklersUnpicklers$$anon$1.pickle(Custom.scala:106)
at BillboardsHot100.serialize(Billboards.scala:46)
at BillboardsHot100.checkForChanges(Billboards.scala:40)
at Main$.main(Main.scala:5)
at Main.main(Main.scala)

But if I change the required to type to List[Track] and just call toList before calling it, it works perfectly. Track is this case class:

case class Track(title: String, artist: String) {
    override def toString()  = title + ", " + artist;
}

Am I doing something wrong or is this a limitation of pickling?

0

There are 0 answers