Skip to content

Instantly share code, notes, and snippets.

View playbyexample-admin's full-sized avatar

playbyexample-admin

View GitHub Profile
@mandubian
mandubian / CODE.scala
Last active December 14, 2015 09:29 — forked from zxamplez/CODE
#Play2.1 #Json Read 2 fields exclusively (accepts only one present) essaimodif #scala #nullable
import play.api.libs.json._
import play.api.libs.functional.syntax._
val r = (
(__ \ "field1").readNullable[String] and
(__ \ "field2").readNullable[Int]
).tupled.filter(ValidationError("unexpected result")){
case( Some(x), None ) => true;
case ( None, Some(x) ) => true;
case _ => false