-1

我花了这么多时间,仍然不明白这里有什么问题。所以我有一个数据看起来像的集合:

{ "_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 中的一些数据与就业类不匹配,但是 Option[] evrywhere,所以......

4

1 回答 1

0

转到它爆炸的地方并打印_id无法反序列化的文档的值?

于 2015-06-30T01:53:04.290 回答