/ / GridFS से फ़ाइल मेटाडेटा की सूची लौटाते हुए - कोई जोंस डिसेरिअलाइज़र - स्केला, प्लेफ्रामवर्क-2.0, प्रतिक्रियाशील

ग्रिडएफएस से फ़ाइल मेटाडेटा की एक सूची लौटाना - कोई जेसन deserializer - स्कैला, playframework-2.0, reactivemongo

यह एक सरल कार्य है, जिसमें शायद भोले का दृष्टिकोण है। मापदंड से मेल खाने वाली सभी फ़ाइलें प्राप्त करें। फ़ाइलों के साथ मेरा मतलब है कि फ़ाइल मेटाडेटा - बाइनरी नहीं है।

for {
files <- gfs.find(BSONDocument("metadata.ideaId" -> BSONObjectID(ideaId))).collect[Seq]()
} yield {

Ok(Json.toJson(files))
}

मेरे पास प्रतिक्रियाशील mongo.api.gridfs.Implicits._ गुंजाइश है लेकिन मुझे मिलता है

No Json deserializer found for type Seq[reactivemongo.api.gridfs.ReadFile[reactivemongo.bson.BSONValue]]

उत्तर:

उत्तर № 1 के लिए 4

मैं इस कार्य के लिए बहुत ही सरल हाथ से बने धारावाहिक का उपयोग करता हूँ

import play.api.libs.json._
import play.api.libs.json.Json._
import reactivemongo.api.gridfs.ReadFile
import reactivemongo.bson.{BSONValue, BSONObjectID}

implicit val fileWrites = new Writes[ReadFile[BSONValue]] {
def writes(file: ReadFile[BSONValue]): JsValue = {
val id = file.id.asInstanceOf[BSONObjectID].stringify
obj(
"_id" -> id, // need it with underscore
"name" -> file.filename,
"url" -> routes.Files.serveFile(id).url, // app specific
"thumbnailUrl" -> routes.Files.serveFile(id).url, // app specific
"extension" -> file.filename.split(".").last,
"contentType" -> file.contentType,
"size" -> file.length,
"uploadDate" -> file.uploadDate,
"deleteUrl" -> "", // app specific
"deleteType" -> "DELETE"
)
}
}

तो आप इसे इस तरह से उपयोग कर सकते हैं:

import helpers.Formats.fileWrites // your package here

def all = Action.async { request =
gfs.find(query).collect[List]() map {
case files: List[ReadFile[BSONValue]] => Ok(prettyPrint(obj("files" -> toJson(files))))
}

उत्तर № 2 के लिए 1

आप "फाइलें" क्रमबद्ध करने की कोशिश करते हैं जो कि एJSON के लिए Seq [reactivemongo.api.gridfs.ReadFile [reactivemongo.bson.BSONValue]] जो बॉक्स से बाहर संभव नहीं है। आपको इसके लिए एक अंतर्निहित JSON सीरीकेज़र (play.api.libs.json.Writes [Seq [ReadFile [BSONValue]]]] के रूप में) प्रदान करना होगा।

देख http://www.playframework.com/documentation/2.1.3/ScalaJson

एक खंड "JsValue के लिए एक स्केल मान परिवर्तित करना" है जो विवरण का वर्णन करता है।