aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2018-02-14 13:46:19 -0800
committerJakob Odersky <jakob@odersky.com>2018-02-14 13:46:19 -0800
commit5a37bfee89a2b5ae17c7980327a92c381c006cf7 (patch)
treec1a2325cb15a79871077ccef89f2761e2f8b0bd4
parent71feac906504271c06076de3dd69ea6297f373e9 (diff)
downloadspray-json-derivation-5a37bfee89a2b5ae17c7980327a92c381c006cf7.tar.gz
spray-json-derivation-5a37bfee89a2b5ae17c7980327a92c381c006cf7.tar.bz2
spray-json-derivation-5a37bfee89a2b5ae17c7980327a92c381c006cf7.zip
Prepare for release
-rw-r--r--.travis.yml2
-rw-r--r--README.md37
-rw-r--r--src/main/scala/DerivedFormats.scala2
3 files changed, 37 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml
index 6305657..a0e5784 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,6 +14,6 @@ cache:
- "$HOME/.sbt/boot/"
before_cache:
- - find $HOME/.ivy2/cache/xyz.driver -depth -name "tracing*" -exec rm -r {} \;
+ - find $HOME/.ivy2/cache/xyz.driver -depth -name "spray-json-derivation*" -exec rm -r {} \;
- find $HOME/.ivy2 -name "ivydata-*.properties" -delete
- find $HOME/.sbt -name "*.lock" -delete
diff --git a/README.md b/README.md
index af518c8..9cc0cce 100644
--- a/README.md
+++ b/README.md
@@ -28,19 +28,50 @@ import xyz.driver.json.DerivedFormats
object Main extends App with DefaultJsonProtocol with DerivedFormats {
+ // Simple case classes
+
case class A(x: Int)
case class B(a: A, str: String)
-
+
println(B(A(42), "hello world").toJson.prettyPrint)
+ // {
+ // "a": {
+ // "x": 42
+ // },
+ // "str": "hello world"
+ // }
+
+
+ // Sealed traits
+
+ sealed trait X
+ case class Y(x: Int) extends X
+ case class Z(y: Y, str: String) extends X
+
+ println(Seq[X](Z(Y(42), "foo"), Y(2)).toJson.prettyPrint)
+ // [{
+ // "type": "Z",
+ // "y": {
+ // "x": 42
+ // },
+ // "str": "foo"
+ // }, {
+ // "type": "Y",
+ // "x": 2
+ // }]
}
```
-
## 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 overview of the project.
+[test suite](src/test/scala/ProductTypeFormats.scala) for a complete
+overview of the project.
+
+## Development
+This project uses sbt. It is set up to auto-release when a tag is
+pushed to the main repository.
## Copying
Copyright 2018 Driver Inc.
diff --git a/src/main/scala/DerivedFormats.scala b/src/main/scala/DerivedFormats.scala
index 79c1e4d..08c452c 100644
--- a/src/main/scala/DerivedFormats.scala
+++ b/src/main/scala/DerivedFormats.scala
@@ -5,6 +5,8 @@ import spray.json._
import scala.language.experimental.macros
+/** Mixin that enables automatic derivation of JSON formats for any product
+ * (case classes) or coproduct (sealed traits) types. */
trait DerivedFormats { self: BasicFormats =>
type Typeclass[T] = JsonFormat[T]