diff options
Diffstat (limited to 'shared/src/test/scala/ProductTypeFormatTests.scala')
-rw-r--r-- | shared/src/test/scala/ProductTypeFormatTests.scala | 24 |
1 files changed, 24 insertions, 0 deletions
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}""" + ) + } |