不能pickle数组,但可以使用Pickling在Scala中腌制List

时间:2013-12-30 14:18:08

标签: java scala scala-pickling

我写了这个方法:

    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();
}

这给了我这个错误:

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)

但是如果我将所需的类型更改为List [Track]并在调用之前调用toList,它就可以完美地运行。 Track就是这个案例类:

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

我做错了什么或这是酸洗的限制?

0 个答案:

没有答案