typeclass-based utility for encoding and decoding mongo db objects in Scala