diff options
author | Dan Checkoway <dcheckoway@gmail.com> | 2015-04-25 10:52:31 -0400 |
---|---|---|
committer | Dan Checkoway <dcheckoway@gmail.com> | 2015-04-27 07:25:49 -0400 |
commit | 4a6263779219fe498039b60fceefddfa4f1ba2a3 (patch) | |
tree | ac558972916ac38958ddcb0a6d07be575f46d0af /src/test | |
parent | f56576932f98227ef1bd37981a46562d053f8409 (diff) | |
download | spray-json-4a6263779219fe498039b60fceefddfa4f1ba2a3.tar.gz spray-json-4a6263779219fe498039b60fceefddfa4f1ba2a3.tar.bz2 spray-json-4a6263779219fe498039b60fceefddfa4f1ba2a3.zip |
Expose fieldName when able in deserialization errors
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/spray/json/ProductFormatsSpec.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/test/scala/spray/json/ProductFormatsSpec.scala b/src/test/scala/spray/json/ProductFormatsSpec.scala index a290604..ba9d907 100644 --- a/src/test/scala/spray/json/ProductFormatsSpec.scala +++ b/src/test/scala/spray/json/ProductFormatsSpec.scala @@ -23,6 +23,7 @@ class ProductFormatsSpec extends Specification { case class Test0() case class Test2(a: Int, b: Option[Double]) case class Test3[A, B](as: List[A], bs: List[B]) + case class Test4(t2: Test2) case class TestTransient(a: Int, b: Option[Double]) { @transient var c = false } @@ -35,6 +36,7 @@ class ProductFormatsSpec extends Specification { implicit val test0Format = jsonFormat0(Test0) implicit val test2Format = jsonFormat2(Test2) implicit def test3Format[A: JsonFormat, B: JsonFormat] = jsonFormat2(Test3.apply[A, B]) + implicit def test4Format = jsonFormat1(Test4) implicit def testTransientFormat = jsonFormat2(TestTransient) implicit def testStaticFormat = jsonFormat2(TestStatic) implicit def testMangledFormat = jsonFormat1(TestMangled) @@ -71,6 +73,16 @@ class ProductFormatsSpec extends Specification { "throw a DeserializationException if the JsValue is not a JsObject" in ( JsNull.convertTo[Test2] must throwA(new DeserializationException("Object expected in field 'a'")) ) + "expose the fieldName in the DeserializationException when able" in { + JsNull.convertTo[Test2] must throwA[DeserializationException].like { + case DeserializationException(_, _, fieldNames) => fieldNames mustEqual "a" :: Nil + } + } + "expose all gathered fieldNames in the DeserializationException" in { + JsObject("t2" -> JsObject("a" -> JsString("foo"))).convertTo[Test4] must throwA[DeserializationException].like { + case DeserializationException(_, _, fieldNames) => fieldNames mustEqual "t2" :: "a" :: Nil + } + } } "A JsonProtocol mixing in NullOptions" should { |