Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DQCategory.scala
- case class DQCategory (
- id : Option[BSONObjectID],
- title : String,
- sentences : List[DailyQuotesSentence]
- )
- object DQCategory {
- implicit object DQCategoryBSONReader extends BSONDocumentReader[DQCategory] {
- def read (doc: BSONDocument): DQCategory = {
- DQCategory (
- doc.getAs[BSONObjectID]("id"),
- doc.getAs[String]("title").get,
- doc.getAs[List[DailyQuotesSentence]]("sentences").toList.flatten
- )
- }
- }
- }
- // DQSentence.scala
- case class DQSentence(
- id : Option[BSONObjectID],
- link : String,
- xpath : String,
- content : String,
- categories : List[DQCategory]
- )
- object DQSentence {
- implicit object DQSentenceBSONReader extends BSONDocumentReader[DQSentence] {
- def read (doc: BSONDocument): DQSentence = {
- DQSentence (
- doc.getAs[BSONObjectID]("id"),
- doc.getAs[String]("link").get,
- doc.getAs[String]("xpath").get,
- doc.getAs[String]("content").get,
- doc.getAs[List[DQCategory]]("categories").toList.flatten
- )
- }
- }
- implicit object DQSentenceBSONWriter extends BSONDocumentWriter[DQSentence] {
- def write(sentence: DQSentence): BSONDocument = {
- BSONDocument (
- "id" -> sentence.id.getOrElse(BSONObjectID.generate),
- "link" -> sentence.link,
- "xpath" -> sentence.xpath,
- "content" -> sentence.content,
- "categories" -> sentence.categories
- )
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement