Skip to content

Instantly share code, notes, and snippets.

@colinpollock
Created March 7, 2012 07:15
Show Gist options
  • Save colinpollock/1991600 to your computer and use it in GitHub Desktop.
Save colinpollock/1991600 to your computer and use it in GitHub Desktop.
Causing a ClassCastException by trying to deserialize a Map[String, Seq[String]]
package com.salattest
import com.mongodb.casbah.Imports._
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.dao._
case class Data (
_id: String,
data: Map[String, Seq[String]]
)
object DataDAO extends SalatDAO[Data, String] (
collection = MongoConnection()("salat_test")("data")
)
object Sal {
def main(args: Array[String]): Unit = {
val data = Data("String->List[String]", Map("a" -> Seq("ant", "all"),
"b" -> Seq("ball", "bore"),
"c" -> Seq("car", "cent")))
DataDAO.insert(data)
DataDAO.findOneByID("String->List[String]") match {
case None => println("not found in db?")
case Some(dat) => {
// The keys are printed out fine
println("KEYS")
dat.data.keys.foreach(k => println(" " + k))
// This causes a ClassCastException
println("VALUES")
dat.data.values.foreach(v => println(" " + v))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment