Domanda

I have an id which is Long. But if I getAs[String], it blindly returns Some(0) instead of None. It checks the presence of the key and not the type.

scala> collection
res26: com.mongodb.DBObject = { "_id" : { "$oid" : "520f8bf544ae41ec63d02eec"} , "date_about" : "2013-08-17T20:13:00.365Z" , "date_created" : "2013-08-17T20:13:00.365Z" , "date_modified" : "2013-09-07T18:03:20.101Z" , "id" : 0 , "node_type" : "meta-folder" , "parent_id" : 0 , "title" : "my stuff, renamed by ajax, wow" , "version" : 2}

scala> collection.getAs[String]("id")
res27: Option[String] = Some(0)

scala> collection.getAs[Long]("id")
res28: Option[Long] = Some(0) //get-ing this is an java.lang.ClassCastException

scala> collection.getAs[Long]("id").get
res29: Long = 0

Is this not unexpected behavior; should I not have got a Option[String] = None? How do i get the expected behavior? I sbt-ed "org.mongodb" %% "casbah" % "2.6.2"

È stato utile?

Soluzione

I've added a ticket to Casbahs issue tracker: SCALA-136 and will fix in the Casbah 2.7.0 release.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top