0

I'm currently working on simple project in Play Framework 2.3.6 with reactivemongo "org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23" and I have problem with nested structure.

My goal is to map such as JSON structure (to Scala equivalent):

{
    _id: ObjectId,
    url: String,
    description: String,
    visitors: [
        _id: ObjectId,
        isFirstTime: Boolean
    ]
}

My Scala code:

import play.api.libs.json.Json
import play.modules.reactivemongo.json.BSONFormats._
import reactivemongo.bson._
import reactivemongo.bson.BSONObjectID

case class Visitor(_id: BSONObjectID, isFirstTime: Boolean)
case class Project(_id: BSONObjectID, url: String, description: String, visitors: List[Visitor])

object JSONFormats {
    implicit val projectFormat = Json.format[Project]
}

In the last line the following error appears : "No implicit format for List[models.Visitor] available."

How can I fix this?

1 Answer 1

1

Add a formatter for Visitor. Idiomatically, these should go in the companion objects.

object Visitor {
  implicit val fmt = Json.format[Visitor]
}

object Project {
  implicit val fmt = Json.format[Project]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.