Play 2.3 with ReactiveMongo to serialize JsObject

73 Views Asked by At

I have a case class like this:

case class MemberOptions(
  @Key("_id") memberId: Long,
  settingsJson: JsObject,
  updateDate: DateTime = DateTime.now()
)

How can I serialize and deserialize JsObject? I tried to look for Writes and Reads but found nothing yet. There is one plugin reactivemongo-play-json but it is for 2.4 only.

I decided to convert to String if there is no better solution.

import reactivemongo.bson._

implicit object JsObjectHandler extends BSONHandler[BSONString, JsObject] {
  override def read(bson: BSONString): JsObject = Json.parse(bson.value).as[JsObject]
  override def write(jsObject: JsObject): BSONString = BSONString(jsObject.toString)
}

implicit val handler = Macros.handler[MemberOptions]
0

There are 0 best solutions below