我花了很多时间,仍然不明白这里的问题。 所以我有一个数据集合的集合:
{ "_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"}}
]}}
我也有SalatDAO用于该系列:
object ProfileDAO extends SalatDAO[Profile, ObjectId](
collection = MongoFactory.getDB("profiles"))
当然还有一堆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])
最后就业类:
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]
)
当我尝试做这样的事情时,我会这样做:
ProfileDAO.findAll().take(20).map(
profile => profile.employment.map(
employment => employment.data.map(
employmentData => employmentData.value.name)))
.foreach(println)
我得到例外:com.mongodb.BasicDBObject cannot be cast to com....Employment
我只有一个想法 - DBCollection中的一些数据与Employment类不匹配,但是还有Option [] evrywhere,所以......
答案 0 :(得分:0)
转到它正在爆炸的位置并打印未能反序列化的文档的_id
值?