diff options
author | Mathias <mathias@spray.cc> | 2011-08-23 16:19:53 +0200 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-08-23 16:26:41 +0200 |
commit | d0267d032a82508d703e5331d92e5e490591f268 (patch) | |
tree | deaeada7843096e026063aa46731a9b2005bd305 /README.markdown | |
parent | 253b8017cf6a5b07f523255f5f82ce0e05361b1b (diff) | |
download | spray-json-d0267d032a82508d703e5331d92e5e490591f268.tar.gz spray-json-d0267d032a82508d703e5331d92e5e490591f268.tar.bz2 spray-json-d0267d032a82508d703e5331d92e5e490591f268.zip |
Add test for generic functionality, add description to README
Diffstat (limited to 'README.markdown')
-rw-r--r-- | README.markdown | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/README.markdown b/README.markdown index 9b150ea..ef48db5 100644 --- a/README.markdown +++ b/README.markdown @@ -94,7 +94,18 @@ If your custom type `T` is a case class then augmenting the `DefaultJsonProtocol val json = Color("CadetBlue", 95, 158, 160).toJson val color = json.fromJson[Color] -The `jsonFormat` method reduces the boilerplate to a minimum, just pass it the companion object of your case class as well as the field names (in order) and it will return a ready-to-use `JsonFormat` for your type. +The `jsonFormat` method reduces the boilerplate to a minimum, just pass it the companion object of your case class as +well as the field names (in order) and it will return a ready-to-use `JsonFormat` for your type. + +If your case class is generic in that it takes type parameters itself the `jsonFormat` method can also help you. +However, there is a little something more boilerplate required as you need to add context bounds for all type parameters +and explicitly refer to the case classes `apply` method as in this example: + + case class NamedList[A](name: String, items: List[A]) + + object MyJsonProtocol extends DefaultJsonProtocol { + implicit def namedListFormat[A :JsonFormat] = jsonFormat(NamedList.apply[A], "name", "items") + } ### Providing JsonFormats for other Types |