diff options
author | Chris Martin <ch.martin@gmail.com> | 2014-09-15 16:48:00 -0400 |
---|---|---|
committer | Chris Martin <ch.martin@gmail.com> | 2014-09-15 16:51:43 -0400 |
commit | 12d83eb4b4b7c749cafe34f4a557c5ce153e4cdf (patch) | |
tree | 8f92c711d5e55811ac96f2e15a75f0d73a3eb687 /src/test/scala | |
parent | 8dc25d6d15a0dbd5d444b83a5d91768e2237495c (diff) | |
download | spray-json-12d83eb4b4b7c749cafe34f4a557c5ce153e4cdf.tar.gz spray-json-12d83eb4b4b7c749cafe34f4a557c5ce153e4cdf.tar.bz2 spray-json-12d83eb4b4b7c749cafe34f4a557c5ce153e4cdf.zip |
Add jsonFormat0 for fieldless case classes
Closes #41
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/spray/json/ProductFormatsSpec.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/scala/spray/json/ProductFormatsSpec.scala b/src/test/scala/spray/json/ProductFormatsSpec.scala index 8e3390d..c4bb489 100644 --- a/src/test/scala/spray/json/ProductFormatsSpec.scala +++ b/src/test/scala/spray/json/ProductFormatsSpec.scala @@ -20,6 +20,7 @@ import org.specs2.mutable._ 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 TestTransient(a: Int, b: Option[Double]) { @@ -30,6 +31,7 @@ class ProductFormatsSpec extends Specification { trait TestProtocol { this: DefaultJsonProtocol => + implicit val test0Format = jsonFormat0(Test0) implicit val test2Format = jsonFormat2(Test2) implicit def test3Format[A: JsonFormat, B: JsonFormat] = jsonFormat2(Test3.apply[A, B]) implicit def testTransientFormat = jsonFormat2(TestTransient) @@ -162,4 +164,21 @@ class ProductFormatsSpec extends Specification { } } + "A JsonFormat created with `jsonFormat`, for a case class with 0 elements," should { + import TestProtocol1._ + val obj = Test0() + val json = JsObject() + "convert to a respective JsObject" in { + obj.toJson mustEqual json + } + "convert a JsObject to the respective case class instance" in { + json.convertTo[Test0] mustEqual obj + } + "ignore additional members during deserialization" in { + JsObject("a" -> JsNumber(42)).convertTo[Test0] mustEqual obj + } + "throw a DeserializationException if the JsValue is not a JsObject" in ( + JsNull.convertTo[Test0] must throwA(new DeserializationException("Object expected")) + ) + } } |