Exception (missing no-arg constructor): scala.collection.immutable.$colon$colon

503 views
Skip to first unread message

Adrian M

unread,
Jun 19, 2013, 5:25:39 PM6/19/13
to kryo-...@googlegroups.com
Hi
I'm using Scala to serialize List[Report]

Where these are the 2 classes involved:
case class Topic(name:String, queryWords:Set[String])
     and

case class Report(dateRange: org.joda.time.Interval, queryWord: String, topics: Map[Topic,Boolean], allOtherTopics: Map[Topic,Boolean])

It has no problems serializing List[Report], but it cannot read it back in. It throws this exception:
com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): scala.collection.immutable.$colon$colon

This is the code that I used to do the serialization:
  val output = new Output(new FileOutputStream(reportsRootPath + reportsFileName))
  kryo.writeClassAndObject(output, reports)
  output.close()

This is the code I use to do deserialization:
val input = new Input(new FileInputStream(reportsRootPath + reportsFileName))
val zzz=kryo.readClassAndObject(input)
return Some(zzz.asInstanceOf[List[Report]])

I also tried deserializing with (with no success):
      val input = new ObjectInputStream(new FileInputStream(reportsRootPath + reportsFileName))
      val obj:List[Report] = input.readObject().asInstanceOf[List[Report]]
      val obj= input.readObject

I've also looked at this question
http://stackoverflow.com/questions/16490912/how-do-you-deserialize-immutable-collection-using-kryo
but the proposed solution does not compile for me

So how can I deserialize my list of reports?
Thanks

mongonix

unread,
Jun 19, 2013, 5:44:22 PM6/19/13
to kryo-...@googlegroups.com
Hi,

Do not try to serialize Scala classes using Kryo directly. Please use one of dedicated Kryo-based Scala libraries for it, e.g. Chill or akka-kryo-serialization. They are also mentioned on Kryo's home page. They support serialization of all major collections types and classes from Scala.

-Leo

Adrian M

unread,
Jun 20, 2013, 2:59:43 PM6/20/13
to kryo-...@googlegroups.com
Thanks! will give it a try.

For all those interested this is the sbt syntax for the current Chill version (as of June 20, 2013):

libraryDependencies += "com.twitter" % "chill_2.10" % "0.2.3"
Reply all
Reply to author
Forward
0 new messages