Permalink
Browse files

Parsing optional JSON paths should fail with error if the provided va…

…lue is invalid instead of returning None.
  • Loading branch information...
1 parent f0f0832 commit e68041fa735be493c38dbe42e86fa394a7a8ffdc @daggerrz committed Sep 7, 2012
@@ -322,7 +322,7 @@ trait DefaultReads {
implicit def OptionReads[T](implicit fmt: Reads[T]): Reads[Option[T]] = new Reads[Option[T]] {
import scala.util.control.Exception._
- def reads(json: JsValue) = fmt.reads(json).fold( e => JsSuccess(None), v => JsSuccess(Some(v)))
+ def reads(json: JsValue) = fmt.reads(json).fold( e => JsError(e), v => JsSuccess(Some(v)))
}
/**
@@ -24,6 +24,7 @@ object JsonValidSpec extends Specification {
"invalidate wrong simple type conversion" in {
JsString("string").validate[Long] must equalTo(JsError(Seq(JsPath() -> Seq(ValidationError("validate.error.expected.jsnumber")))))
+ JsString("string").validate[Option[Long]] must equalTo(JsError(Seq(JsPath() -> Seq(ValidationError("validate.error.expected.jsnumber")))))
JsNumber(5).validate[String] must equalTo(JsError(Seq(JsPath() -> Seq(ValidationError("validate.error.expected.jsstring")))))
JsBoolean(false).validate[Double] must equalTo(JsError(Seq(JsPath() -> Seq(ValidationError("validate.error.expected.jsnumber")))))
}

0 comments on commit e68041f

Please sign in to comment.