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/test/scala/ProductTypeFormatTests.scala | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'shared/src/test/scala/ProductTypeFormatTests.scala') diff --git a/shared/src/test/scala/ProductTypeFormatTests.scala b/shared/src/test/scala/ProductTypeFormatTests.scala index 4d71aa3..4c979c0 100644 --- a/shared/src/test/scala/ProductTypeFormatTests.scala +++ b/shared/src/test/scala/ProductTypeFormatTests.scala @@ -90,4 +90,28 @@ class ProductTypeFormatTests assert("{}".parseJson.convertTo[Opt] == Opt(None)) } + case class Typed[T](t: T) + + implicit def typed[T: JsonFormat] = jsonFormat[Typed[T]] + + "Class with a type parameter" should behave like checkRoundtrip( + Typed[Int](42), + """{"t":42}""" + ) + + "Class with nested types" should behave like checkRoundtrip( + Typed[Typed[String]](Typed("hello world")), + """{"t":{"t":"hello world"}}""" + ) + + case class Phantom[T](x: Int) + + // no json format required for T + implicit def phantom[T] = jsonFormat[Phantom[T]] + + "Phantom types without a format" should behave like checkRoundtrip( + Phantom[Int => String](42), // the given type parameter should not have a format + """{"x":42}""" + ) + } -- cgit v1.2.3