1

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]
cchantep
  • 9,118
  • 3
  • 30
  • 41
angelokh
  • 9,426
  • 9
  • 69
  • 139
  • The ReactiveMongo plugin for 2.3 provides such conversion, even if that's recommended to upgrade you Play version to fix such tech debt – cchantep Jul 18 '17 at 10:55

0 Answers0