Felix
Felix

Reputation: 5629

playframework scala validate case class in tests

Hi I try to validate in a test the test result in my scala playframework application.

My code looks like this:

implicit val clientIdFormat = Json.format[clientId]

case class clientId(id: Int)

and in the test:

  val content = contentAsJson(result).validate(clientId).asOpt.orNull

error is type mismatch

enter image description here

what could be my fail in this case?

Upvotes: 0

Views: 70

Answers (1)

Tzach Zohar
Tzach Zohar

Reputation: 37842

The method validate expects a type parameter, not an argument:

def validate[A](implicit rds: Reads[A]): JsResult[A] = rds.reads(this)

So, you should call it using [clientId] and not (clientId):

val content = contentAsJson(result).validate[clientId].asOpt.orNull

Upvotes: 4

Related Questions