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 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'shared/src/main/scala/DerivedFormats.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"""{ -- cgit v1.2.3