diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-02-14 12:17:15 -0800 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-02-14 12:17:15 -0800 |
commit | eada4c48b3954241e130f5d9b5e7feebe8c1e3f2 (patch) | |
tree | d017b30fb264b0560cbf7df3540f26e705da8ec0 /src/main/scala/annotations.scala | |
parent | af6845cc08ae223ad67ebad61559d8264fd3346b (diff) | |
download | spray-json-derivation-eada4c48b3954241e130f5d9b5e7feebe8c1e3f2.tar.gz spray-json-derivation-eada4c48b3954241e130f5d9b5e7feebe8c1e3f2.tar.bz2 spray-json-derivation-eada4c48b3954241e130f5d9b5e7feebe8c1e3f2.zip |
Prepare for releasing
Diffstat (limited to 'src/main/scala/annotations.scala')
-rw-r--r-- | src/main/scala/annotations.scala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/scala/annotations.scala b/src/main/scala/annotations.scala new file mode 100644 index 0000000..f23fbcb --- /dev/null +++ b/src/main/scala/annotations.scala @@ -0,0 +1,33 @@ +package xyz.driver.json + +import scala.annotation.StaticAnnotation + +/** Indicator trait of anontations related to JSON formatting. */ +sealed trait JsonAnnotation + +/** 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 + with JsonAnnotation + +/** An annotation that designates that a sealed trait is an enumeration (all + * children are strictly case objects), and that all children should be + * serialized as strings. */ +final class enum extends StaticAnnotation with JsonAnnotation |