From c4dd18f810afdb4adb85d002ad34e660fe54c146 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Fri, 29 Jun 2018 17:56:06 -0700 Subject: Fix bug in derivation of classes with type parameters --- shared/src/main/scala/DerivedFormats.scala | 17 +++++++++++------ shared/src/main/scala/annotations.scala | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'shared/src/main/scala') diff --git a/shared/src/main/scala/DerivedFormats.scala b/shared/src/main/scala/DerivedFormats.scala index 03e632f..6ea7c4b 100644 --- a/shared/src/main/scala/DerivedFormats.scala +++ b/shared/src/main/scala/DerivedFormats.scala @@ -18,7 +18,8 @@ trait DerivedFormats { self: BasicFormats => override def write(value: T): JsValue = { val fields: Seq[(String, JsValue)] = ctx.parameters.map { param => extractFieldName(param.label) -> param.typeclass.write( - param.dereference(value)) + param.dereference(value) + ) } JsObject(fields: _*) } @@ -40,7 +41,8 @@ trait DerivedFormats { self: BasicFormats => } case js => deserializationError( - s"Cannot read JSON '$js' as a ${ctx.typeName.full}") + s"Cannot read JSON '$js' as a ${ctx.typeName.full}" + ) } } @@ -57,7 +59,8 @@ trait DerivedFormats { self: BasicFormats => case obj: JsObject => JsObject( (Map(typeFieldName -> JsString(sub.typeName.short)) ++ - obj.fields).toSeq: _*) + obj.fields).toSeq: _* + ) case js => js } } @@ -71,7 +74,8 @@ trait DerivedFormats { self: BasicFormats => case _ => deserializationError( s"Cannot deserialize JSON to ${ctx.typeName.full} " + - "because serialized type cannot be determined.") + "because serialized type cannot be determined." + ) } ctx.subtypes.find(_.typeName.short == typeName) match { @@ -79,7 +83,8 @@ trait DerivedFormats { self: BasicFormats => case None => deserializationError( s"Cannot deserialize JSON to ${ctx.typeName.full} " + - s"because type '${typeName}' is unsupported.") + s"because type '${typeName}' is unsupported." + ) } } } @@ -117,7 +122,7 @@ object DerivedFormatMacros { /** Utility that converts a magnolia-generated JsonFormat to a RootJsonFormat. */ def derivedFormat[T: c.WeakTypeTag](c: Context): c.Tree = { import c.universe._ - val tpe = weakTypeOf[T].typeSymbol.asType + val tpe = weakTypeOf[T] val sprayPkg = c.mirror.staticPackage("spray.json") val valName = TermName(c.freshName("format")) q"""{ diff --git a/shared/src/main/scala/annotations.scala b/shared/src/main/scala/annotations.scala index 9d35d16..1b7c62c 100644 --- a/shared/src/main/scala/annotations.scala +++ b/shared/src/main/scala/annotations.scala @@ -3,13 +3,13 @@ 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. + * datatype (GADT), 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 * 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. + * that would otherwise result in a conflict. * * Example: * {{{ -- cgit v1.2.3