I am trying to build a simple validator for incoming JSON.
I want to check that the JsObject has only one field "name" which is a non empty String.
import play.api.libs.json.Reads._
import play.api.libs.json._
val myRead = ( __ \ "name" ).json.pickBranch[JsString](minLength(1))
I would expect myRead to be a Reads[JsObject] or something similar but what I get instead is a compilation error:
diverging implicit expansion for type play.api.libs.json.Reads[M] starting with method ArrayReads in trait DefaultReads
how to get rid of that problem?
Ok, turned out that minLength simply does not work with JsString.
Ended up with a following solution:
works perfectly, although I miss some "standard" validations here.