diff options
author | Mathias <mathias@spray.cc> | 2011-10-04 09:27:03 +0200 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-10-04 09:27:03 +0200 |
commit | 758e17d8c780ab44befc26a18344367f70334c56 (patch) | |
tree | 4ac0f895423be392995ef686fc6e770556a98026 /src/test/scala/cc/spray/json | |
parent | e963029528d770749154a56169ddaa7a098ebd67 (diff) | |
download | spray-json-758e17d8c780ab44befc26a18344367f70334c56.tar.gz spray-json-758e17d8c780ab44befc26a18344367f70334c56.tar.bz2 spray-json-758e17d8c780ab44befc26a18344367f70334c56.zip |
Add NullOptions trait
Diffstat (limited to 'src/test/scala/cc/spray/json')
-rw-r--r-- | src/test/scala/cc/spray/json/ProductFormatsSpec.scala | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/test/scala/cc/spray/json/ProductFormatsSpec.scala b/src/test/scala/cc/spray/json/ProductFormatsSpec.scala index 221d8ae..9a692ec 100644 --- a/src/test/scala/cc/spray/json/ProductFormatsSpec.scala +++ b/src/test/scala/cc/spray/json/ProductFormatsSpec.scala @@ -2,15 +2,21 @@ package cc.spray.json import org.specs2.mutable._ -class ProductFormatsSpec extends Specification with DefaultJsonProtocol { +class ProductFormatsSpec extends Specification { 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") - + + trait TestProtocol { + this: DefaultJsonProtocol => + implicit val test2Format = jsonFormat(Test2, "a", "b") + implicit def test3Format[A: JsonFormat, B: JsonFormat] = jsonFormat(Test3.apply[A, B], "as", "bs") + } + object TestProtocol1 extends DefaultJsonProtocol with TestProtocol + object TestProtocol2 extends DefaultJsonProtocol with TestProtocol with NullOptions + "A JsonFormat created with `jsonFormat`, for a case class with 2 elements," should { + import TestProtocol1._ val obj = Test2(42, Some(4.2)) val json = JsObject(JsField("a", 42), JsField("b", 4.2)) "convert to a respective JsObject" in { @@ -40,7 +46,15 @@ class ProductFormatsSpec extends Specification with DefaultJsonProtocol { ) } + "A JsonProtocol mixing in NullOptions" should { + "render `None` members to `null`" in { + import TestProtocol2._ + Test2(42, None).toJson mustEqual JsObject(JsField("a", 42), JsField("b", JsNull)) + } + } + "A JsonFormat for a generic case class and created with `jsonFormat`" should { + import TestProtocol1._ val obj = Test3(42 :: 43 :: Nil, "x" :: "y" :: "z" :: Nil) val json = JsObject( JsField("as", JsArray(JsNumber(42), JsNumber(43))), |