aboutsummaryrefslogtreecommitdiff
path: root/shared/src/main/scala/annotations.scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2018-03-08 16:53:44 -0800
committerJakob Odersky <jakob@odersky.com>2018-03-28 10:34:31 -0700
commitc5fe23594f66225eb18bf4e67472cd80023eb448 (patch)
tree58fe8509b3990932134c18e09ed69ee83b779373 /shared/src/main/scala/annotations.scala
parent2f3f9aa851080b6c79f3af14b3fdfeab56feffec (diff)
downloadspray-json-derivation-c5fe23594f66225eb18bf4e67472cd80023eb448.tar.gz
spray-json-derivation-c5fe23594f66225eb18bf4e67472cd80023eb448.tar.bz2
spray-json-derivation-c5fe23594f66225eb18bf4e67472cd80023eb448.zip
Refactor build to use sbt-crossproject
Diffstat (limited to 'shared/src/main/scala/annotations.scala')
-rw-r--r--shared/src/main/scala/annotations.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/shared/src/main/scala/annotations.scala b/shared/src/main/scala/annotations.scala
new file mode 100644
index 0000000..9d35d16
--- /dev/null
+++ b/shared/src/main/scala/annotations.scala
@@ -0,0 +1,22 @@
+package spray.json
+
+import scala.annotation.StaticAnnotation
+
+/** An annotation that designates that a sealed trait is a generalized algebraic
+ * datatype (GADT), and that a type field containing the serialized childrens'
+ * types should be added to the final JSON objects.
+ *
+ * Note that by default all sealed traits are treated as GADTs, with a type
+ * field called `type`. This annotation enables overriding the name of that
+ * field and is really only useful if a child itself has a field called `type`
+ * that would result in a conflict.
+ *
+ * Example:
+ * {{{
+ * // the JSON field "kind" will contain the actual type of the serialized child
+ * @gadt("kind") sealed abstract class Keyword(`type`: String)
+ * case class If(`type`: String) extends Keyword(`type`)
+ * }}}
+ * @param typeFieldName the name of the field to inject into a serialized JSON
+ * object */
+final class gadt(val typeFieldName: String = "type") extends StaticAnnotation