From 5a37bfee89a2b5ae17c7980327a92c381c006cf7 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 14 Feb 2018 13:46:19 -0800 Subject: Prepare for release --- .travis.yml | 2 +- README.md | 37 ++++++++++++++++++++++++++++++++++--- src/main/scala/DerivedFormats.scala | 2 ++ 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] -- cgit v1.2.3