diff options
author | Mathias <mathias@spray.cc> | 2011-11-16 09:38:34 +0100 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-11-16 09:38:34 +0100 |
commit | 2f31d74fad963561f646802a0a0fc194f430b573 (patch) | |
tree | 48ce470fa4507b681a09c90e4b93bdbf829b892f /src/test | |
parent | c14e3c5fec716d32cfd7a3d358e527c1c6b24a15 (diff) | |
download | spray-json-2f31d74fad963561f646802a0a0fc194f430b573.tar.gz spray-json-2f31d74fad963561f646802a0a0fc194f430b573.tar.bz2 spray-json-2f31d74fad963561f646802a0a0fc194f430b573.zip |
Add test for lazyFormat wrapper (recursive JsonFormats)
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala b/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala index 0db3d5a..1f5362a 100644 --- a/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala +++ b/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala @@ -38,4 +38,18 @@ class AdditionalFormatsSpec extends Specification { JsonParser("""{"content":{"content":[1,2,3]}}""").convertTo[Container[Container[List[Int]]]] mustEqual obj } } + + case class Foo(id: Long, name: String, foos: Option[List[Foo]] = None) + + object FooProtocol extends DefaultJsonProtocol { + implicit val FooProtocol: JsonFormat[Foo] = lazyFormat(jsonFormat(Foo, "id", "name", "foos")) + } + + "The lazyFormat wrapper" should { + "enable recursive format definitions" in { + import FooProtocol._ + Foo(1, "a", Some(Foo(2, "b", Some(Foo(3, "c") :: Nil)) :: Foo(4, "d") :: Nil)).toJson.toString mustEqual + """{"id":1,"name":"a","foos":[{"id":2,"name":"b","foos":[{"id":3,"name":"c"}]},{"id":4,"name":"d"}]}""" + } + } }
\ No newline at end of file |