Hi.
I am using Play JSON 2.6.10. Currently the 2-arity methods mentioned above do not use by-name parameters for the error case:
def collect[B](otherwise: JsonValidationError)(p: PartialFunction[A, B]): JsResult[B]
This comes to me a bit as a surprise, as the error case is always evaluated.
In our case, we wanted to use side-effects, ie. log a warning when validation failed:
val result = for {
provider ← (v \ "provider").validate[String]
} yield provider match {
case "whatever" => Some(Whatever)
}
result.collect {
logger.warn("could not validate provider: " + v))
JsonValidationError("...")
} {
collect Some(x) => x
}
Now, the warrning is logged for every call of the validation function, regardless whether it failed or not.
Is this something that should / could be changed?
Thanks!