summaryrefslogtreecommitdiff
path: root/README.markdown
diff options
context:
space:
mode:
authorMathias <mathias@spray.cc>2011-11-16 09:46:02 +0100
committerMathias <mathias@spray.cc>2011-11-16 09:46:02 +0100
commit3ada25874b22c492907f1c72572a81726b83aa60 (patch)
treef3753482d5203f89af548b5f0af8f54cc6df2965 /README.markdown
parent2f31d74fad963561f646802a0a0fc194f430b573 (diff)
downloadspray-json-3ada25874b22c492907f1c72572a81726b83aa60.tar.gz
spray-json-3ada25874b22c492907f1c72572a81726b83aa60.tar.bz2
spray-json-3ada25874b22c492907f1c72572a81726b83aa60.zip
Add 'JsonFormats for recursive Types' to README
Diffstat (limited to 'README.markdown')
-rw-r--r--README.markdown14
1 files changed, 14 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index 3550dd1..d8c3986 100644
--- a/README.markdown
+++ b/README.markdown
@@ -172,6 +172,20 @@ This is a bit more verbose in its definition and the resulting JSON but transpor
Note that this is the approach _spray-json_ uses for case classes.
+### JsonFormats for recursive Types
+
+If your type is recursive such as
+
+ case class Foo(i: Int, foo: Foo)
+
+you need to wrap your format constructor with `lazyFormat` and supply an explicit type annotation:
+
+ implicit val fooFormat: JsonFormat[Foo] = lazyFormat(jsonFormat(Foo, "i", "foo"))
+
+Otherwise your code will either not compile (no explicit type annotation) or throw an NPE at runtime (no `lazyFormat`
+wrapper).
+
+
### API Documentation
You can find the documentation for the _spray-json_ API here: