diff options
author | Mathias <mathias@spray.cc> | 2011-05-24 23:02:25 +0200 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-05-24 23:02:25 +0200 |
commit | 57bc594e1daa7dff6013759d6fc65f183118aa33 (patch) | |
tree | f8ad4c437284fb0583a556a98aba74126a988ea3 /src/test/scala/cc/spray/json/ProductFormatsSpec.scala | |
parent | 854700927ca944d684c9e0758b5a52da4dde2609 (diff) | |
download | spray-json-57bc594e1daa7dff6013759d6fc65f183118aa33.tar.gz spray-json-57bc594e1daa7dff6013759d6fc65f183118aa33.tar.bz2 spray-json-57bc594e1daa7dff6013759d6fc65f183118aa33.zip |
Add JsonFormat for JsValues, some more helpers
Diffstat (limited to 'src/test/scala/cc/spray/json/ProductFormatsSpec.scala')
-rw-r--r-- | src/test/scala/cc/spray/json/ProductFormatsSpec.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/ProductFormatsSpec.scala b/src/test/scala/cc/spray/json/ProductFormatsSpec.scala new file mode 100644 index 0000000..5f253c2 --- /dev/null +++ b/src/test/scala/cc/spray/json/ProductFormatsSpec.scala @@ -0,0 +1,31 @@ +package cc.spray.json + +import org.specs.Specification + +class ProductFormatsSpec extends Specification with DefaultJsonProtocol { + + case class Test2(a: Int, b: Double) + implicit val test2Format = jsonFormat(Test2, "a", "b") + + "A JsonFormat created with format, for a case class with 2 elements," should { + val obj = Test2(42, 4.2) + val json = JsObject(JsField("a", 42), JsField("b", 4.2)) + "convert to a respective JsObject" in { + obj.toJson mustEqual json + } + "convert a JsObject to the respective case class instance" in { + json.fromJson[Test2] mustEqual obj + } + "throw a DeserializationException if the JsObject does not define the right members" in ( + JsObject(JsField("a", 42), JsField("x", 4.2)).fromJson[Test2] must + throwA(new DeserializationException("Object is missing required member 'b'")) + ) + "ignore additional members during deserialization" in { + JsObject(JsField("a", 42), JsField("b", 4.2), JsField("c", 'no)).fromJson[Test2] mustEqual obj + } + "throw a DeserializationException if the JsValue is not a JsObject" in ( + JsNull.fromJson[Test2] must throwA(new DeserializationException("Object expected")) + ) + } + +} |