Last active
August 29, 2015 14:06
-
-
Save cvogt/e9da3ebb8790fe2716ee to your computer and use it in GitHub Desktop.
ReactiveMongo reader writer handler to serialize nested seqs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def MapReader[V,B <: BSONValue](implicit vr: BSONReader[B,V]) = new BSONDocumentReader[Seq[(String, V)]] { | |
def read(bson: BSONDocument): Seq[(String, V)] = { | |
val elements = bson.elements.map { tuple => | |
tuple._1 -> tuple._2.seeAsTry(vr).get | |
} | |
elements | |
} | |
} | |
implicit def MapWriter[V,B <: BSONValue](implicit vw: BSONWriter[V,B]) = new BSONDocumentWriter[Seq[(String, V)]] { | |
def write(map: Seq[(String, V)]): BSONDocument = { | |
val elements = map.toStream.map { tuple => | |
tuple._1 -> vw.write(tuple._2) | |
} | |
BSONDocument(elements) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment