1
我的數據庫看起來像斯卡拉薩拉特反序列化:如何獲得一個地圖[字符串,數字]?
[
{
name: "domenic",
records: {
today: 5,
yesterday: 1.5
}
},
{
name: "bob",
records: { ... }
}
]
當我嘗試像
val result: Option[DBObject] = myCollection.findOne(
MongoDBObject("name" -> "domenic")
MongoDBObject("records" -> 1),
)
val records = result.get.getAs[BasicDBObject]("records").get
grater[Map[String, Number]].asObject(records)
失敗查詢(在運行時!)與
GRATER GLITCH - unable to find or instantiate a grater using supplied path name
REASON: Class scala.collection.immutable.Map is an interface
Context: 'global'
Path from pickled Scala sig: 'scala.collection.immutable.Map'
我想我可能會創建一個使這項工作案例類別,其唯一字段是Map[String, Number]
,然後獲取其屬性。這真的有必要嗎?
'Number'是我短時間內使用JSON的唯一方式,否則只要有非小數(例如'[45.4,45.6,45.8,46,46.2]'),它就會拋出異常。 – Domenic
你可以顯示'getAs'代碼的樣子嗎? – Domenic