diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-03-08 16:13:03 -0800 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-03-08 16:21:49 -0800 |
commit | 5ef502abc058358ec3a329c774bb42b9a7bd106f (patch) | |
tree | ee5c20fa79307e1a8397a86f31fbe54cbfe9fe1a /README.md | |
parent | eb1ad3c956c828d421b7650dd3b01d5129a41a3d (diff) | |
download | spray-json-derivation-5ef502abc058358ec3a329c774bb42b9a7bd106f.tar.gz spray-json-derivation-5ef502abc058358ec3a329c774bb42b9a7bd106f.tar.bz2 spray-json-derivation-5ef502abc058358ec3a329c774bb42b9a7bd106f.zip |
Don't ake derived formats implicit by defaultv0.3.0
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -26,14 +26,14 @@ build.sbt: libraryDependencies += "xyz.driver" %% "spray-json-derivation" % "<latest version>" ``` -Define some case classes and mix `DerivedFormats` into your JSON +Define some case classes and mix `ImplicitDerivedFormats` into your JSON protocol stack. That's it. ```scala import spray.json._ -import xyz.driver.json.DerivedFormats +import xyz.driver.json.ImplicitDerivedFormats -object Main extends App with DefaultJsonProtocol with DerivedFormats { +object Main extends App with DefaultJsonProtocol with ImplicitDerivedFormats { // Simple case classes @@ -70,10 +70,27 @@ object Main extends App with DefaultJsonProtocol with DerivedFormats { } ``` +It is also possible to summon derived formats explicitly by mixing in `DerivedFormats`instead of `ImplicitDerivedFormats`: +```scala +import spray.json._ +import xyz.driver.json.DerivedFormats + +object Main extends App with DefaultJsonProtocol with DerivedFormats { + + case class A(x: Int) + case class B(a: A, str: String) + + implicit val bFormat: RootJsonFormat[B] = jsonFormat[B] + + println(B(A(42), "hello world").toJson.prettyPrint) +``` +This will have the additional benefit of outputting a stacktrace in case a format cannot be derived, hence making debugging +much easier. + ## Documentation Check out the main file [DerivedFormats.scala](src/main/scala/DerivedFormats.scala) and the -[test suite](src/test/scala/ProductTypeFormats.scala) for a complete +[test suite](src/test/scala/ProductTypeFormatTests.scala) for a complete overview of the project. ## Development |