From df09f6ed64aad3e83f98e13a3d7d9b3a82ccd0a8 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Fri, 29 Jun 2018 17:56:06 -0700 Subject: Change GADT to ADT --- CHANGELOG.md | 8 +++++--- shared/src/main/scala/DerivedFormats.scala | 2 +- shared/src/main/scala/annotations.scala | 12 ++++++------ shared/src/test/scala/CoproductTypeFormatTests.scala | 8 ++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf4dbd7..b2a309a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -# Version 0.5.0 +# Version UNRELEASED -None values are no longer written to objects by default. This is -configurable by overriding `printNull` in DerivedFormats. +- None values are no longer written to objects by default. This is + configurable by overriding `printNull` in DerivedFormats. + +- Change references of GADTs to ADTs # Version 0.4.7 diff --git a/shared/src/main/scala/DerivedFormats.scala b/shared/src/main/scala/DerivedFormats.scala index ccf48d1..f6a3f7b 100644 --- a/shared/src/main/scala/DerivedFormats.scala +++ b/shared/src/main/scala/DerivedFormats.scala @@ -60,7 +60,7 @@ trait DerivedFormats { self: BasicFormats => def dispatch[T](ctx: SealedTrait[JsonFormat, T]): JsonFormat[T] = { val typeFieldName = ctx.annotations .collectFirst { - case g: gadt => g.typeFieldName + case g: adt => g.typeFieldName } .getOrElse("type") diff --git a/shared/src/main/scala/annotations.scala b/shared/src/main/scala/annotations.scala index 1b7c62c..4437aeb 100644 --- a/shared/src/main/scala/annotations.scala +++ b/shared/src/main/scala/annotations.scala @@ -2,11 +2,11 @@ package spray.json import scala.annotation.StaticAnnotation -/** An annotation that designates that a sealed trait is a generalized algebraic - * datatype (GADT), and that a field containing the serialized childrens' types - * should be added to the final JSON objects. +/** An annotation that designates that a sealed trait is an algebraic datatype + * (ADT), and that a 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 + * Note that by default all sealed traits are treated as ADTs, 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 otherwise result in a conflict. @@ -14,9 +14,9 @@ import scala.annotation.StaticAnnotation * Example: * {{{ * // the JSON field "kind" will contain the actual type of the serialized child - * @gadt("kind") sealed abstract class Keyword(`type`: String) + * @adt("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 +final class adt(val typeFieldName: String = "type") extends StaticAnnotation diff --git a/shared/src/test/scala/CoproductTypeFormatTests.scala b/shared/src/test/scala/CoproductTypeFormatTests.scala index cd6a2ae..7da2041 100644 --- a/shared/src/test/scala/CoproductTypeFormatTests.scala +++ b/shared/src/test/scala/CoproductTypeFormatTests.scala @@ -36,24 +36,24 @@ class CoproductTypeFormatTests """{"type": "One"}""" ) - @gadt("kind") + @adt("kind") sealed abstract class Keyword(`type`: String) case class If(`type`: String) extends Keyword(`type`) implicit val keywordFormat: RootJsonFormat[Keyword] = jsonFormat[Keyword] - "GADT with type field alias" should behave like checkRoundtrip[Keyword]( + "ADT with type field alias" should behave like checkRoundtrip[Keyword]( If("class"), """{"kind":"If","type":"class"}""" ) - @gadt("""_`crazy type!`"""") + @adt("""_`crazy type!`"""") sealed abstract trait Crazy case class CrazyType() extends Crazy implicit val crazyFormat: RootJsonFormat[Crazy] = jsonFormat[Crazy] - "GADT with special characters in type field" should behave like checkRoundtrip[ + "ADT with special characters in type field" should behave like checkRoundtrip[ Crazy ]( CrazyType(), -- cgit v1.2.3