summaryrefslogtreecommitdiff
path: root/src/test/scala/cc/spray/json/ProductFormatsSpec.scala
diff options
context:
space:
mode:
authorMathias <mathias@spray.cc>2011-09-28 15:45:44 +0200
committerMathias <mathias@spray.cc>2011-09-28 15:45:44 +0200
commit6945136f15ca6f6378e79d5ca2708ddf0041102a (patch)
treeafd1566aa28a271d7c979dca7497e0ceb520f493 /src/test/scala/cc/spray/json/ProductFormatsSpec.scala
parent48b6d35942963b412810b3cc61d3c3ca7f79f513 (diff)
downloadspray-json-6945136f15ca6f6378e79d5ca2708ddf0041102a.tar.gz
spray-json-6945136f15ca6f6378e79d5ca2708ddf0041102a.tar.bz2
spray-json-6945136f15ca6f6378e79d5ca2708ddf0041102a.zip
Improve Option handling, speed up case class (de)serialization, closes #5
Diffstat (limited to 'src/test/scala/cc/spray/json/ProductFormatsSpec.scala')
-rw-r--r--src/test/scala/cc/spray/json/ProductFormatsSpec.scala18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/test/scala/cc/spray/json/ProductFormatsSpec.scala b/src/test/scala/cc/spray/json/ProductFormatsSpec.scala
index 763b4b0..221d8ae 100644
--- a/src/test/scala/cc/spray/json/ProductFormatsSpec.scala
+++ b/src/test/scala/cc/spray/json/ProductFormatsSpec.scala
@@ -4,25 +4,31 @@ import org.specs2.mutable._
class ProductFormatsSpec extends Specification with DefaultJsonProtocol {
- case class Test2(a: Int, b: Double)
+ case class Test2(a: Int, b: Option[Double])
implicit val test2Format = jsonFormat(Test2, "a", "b")
case class Test3[A, B](as: List[A], bs: List[B])
implicit def test3Format[A: JsonFormat, B: JsonFormat] = jsonFormat(Test3.apply[A, B], "as", "bs")
"A JsonFormat created with `jsonFormat`, for a case class with 2 elements," should {
- val obj = Test2(42, 4.2)
+ val obj = Test2(42, Some(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
+ 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'"))
+ "throw a DeserializationException if the JsObject does not all required members" in (
+ JsObject(JsField("b", 4.2)).fromJson[Test2] must
+ throwA(new DeserializationException("Object is missing required member 'a'"))
)
+ "not require the presence of optional fields for deserialization" in {
+ JsObject(JsField("a", 42)).fromJson[Test2] mustEqual Test2(42, None)
+ }
+ "not render `None` members during serialization" in {
+ Test2(42, None).toJson mustEqual JsObject(JsField("a", 42))
+ }
"ignore additional members during deserialization" in {
JsObject(JsField("a", 42), JsField("b", 4.2), JsField("c", 'no)).fromJson[Test2] mustEqual obj
}