1

I can't understand how to make validation for class with one field. For example:

case class JGoodNew(
          languageid: Long,
          title: String
        )
val goodNewReads: Reads[JGoodNew] = (
      (JsPath \ "languageid").read[Long] and
      (JsPath \ "title").read[String](minLength[String](2))
    )(JGoodNew.apply _)

This works fine. But this doesn't work:

case class JGoodNew(
          title: String
        )
val goodNewReads: Reads[JGoodNew] = (
      (JsPath \ "title").read[String](minLength[String](2))
    )(JGoodNew.apply _)

Compiler complaining

type mismatch; found : String => validators.JGoodNew required: play.api.libs.json.Reads[?]

Why is this so?

sergeda
  • 1,771
  • 2
  • 15
  • 33

0 Answers0