0

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?

Mr. Adobo
  • 815
  • 1
  • 12
  • 24
  • 2
    (1) nobody can tell you why the assertion failed *if you don't show the assertion*; (2) there's a syntax error in the second line, please copy your actual code; (3) you need to close your `PrintWriter` if you don't want to leak file handles; (4) `PrintWriter` is a bad choice because it uses default encoding; (5) this has nothing to do with Java. – kdgregory Dec 30 '13 at 14:23
  • Only added java cause stack overflow suggested it, and thought it was pertinent since that is java.io.File. The assetion is from the scala library and not mine. Sorry about the syntax error, no idea how it got there. That is my actual code. – Mr. Adobo Dec 30 '13 at 14:26

0 Answers0