Scala Salat BasicDBObject cannot be cast to

245 Views Asked by At

I've spent so much time and still don't understand what the problem here. So I have a collection that data looks like:

{ "_id" : "someId", "employment" : { "data" : [ 
    { "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "city" : "someSity" , "fromMonth" : 0 , "name" : "someName" , "fromYear" : 2011 , "toMonth" : 0 , "speciality" : "someSpeciality"}},
    { "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "city" : "someSity" , "fromMonth" : 7 , "name" : "someName" , "fromYear" : 2013 , "toMonth" : 7 , "toYear" : 2014 , "speciality" : "someSpeciality"}},
    { "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "city" : "someSity" , "fromMonth" : 10 , "name" : "someName" , "fromYear" : 2010 , "toMonth" : 10 , "toYear" : 2010 , "speciality" : "someSpeciality"}}
    { "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "fromMonth" : 2 , "name" : "someName" , "fromYear" : 2007 , "toMonth" : 2 , "toYear" : 2010 , "speciality" : "someSpeciality"}}
]}}

also I have SalatDAO for that collection:

object ProfileDAO extends SalatDAO[Profile, ObjectId](
  collection = MongoFactory.getDB("profiles"))

and ofcourse a bunch of case class:

case class Profile(
  @Key("_id") id: String,
  employment: Option[ListField[Employment]]

case class ListField[T](
  data: List[Value[T]])

case class Value[T](
  value: Option[T],
  retrieved: Option[Instant],
  deleted: Option[Instant])

and finally Employment class:

case class Employment(
   name: Option[String],
   country: Option[String],
   city: Option[String],
   fromMonth: Option[Int],
   toMonth: Option[Int],
   fromYear: Option[Int],
   toYear: Option[Int],
   speciality: Option[String]
   )

Byt when I try do something like this:

ProfileDAO.findAll().take(20).map(
    profile => profile.employment.map(
        employment => employment.data.map(
            employmentData => employmentData.value.name)))
.foreach(println)

I get Exception: com.mongodb.BasicDBObject cannot be cast to com....Employment Only one idea I have - some data in DBCollection don't match with Employment class, but there is Option[] evrywhere, so...

1

There are 1 best solutions below

9
prasinous On

Go to where it's blowing up and print the _id value of the document that's failing to deserialize?