1
votes

I've been trying to use the Reads[A] in Play as discussed in this post.

Handling JSON requests in Play Framework 2.0 Scala

However, when I tried to do something similar, I ended up getting this error.

object creation impossible, since method reads in trait Reads of type (json: play.api.libs.json.JsValue)models.SomeObject.AnotherObject is not defined

I currently have:

package models

object SomeObject {
  case class AnotherObject(val name: String)
  implicit object AnotherObjectReads extends Reads[AnotherObject] {
    def read(json: JsValue) =
      AnotherObject((json \ "name").as[String])
  }
}

And I'm using it in the following way:

def callFunc = Action(BodyParsers.parse.json) { request =>
  request.body.asOpt[SomeObject.AnotherObject].map {
    //Logic
  }.getOrElse(BadRequest)
}

Am I doing something wrong in my code?

1

1 Answers