aboutsummaryrefslogtreecommitdiff
path: root/shared/src/test/scala/ProductTypeFormatTests.scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2018-06-29 17:56:06 -0700
committerJakob Odersky <jakob@odersky.com>2018-06-30 00:32:44 -0700
commitc4dd18f810afdb4adb85d002ad34e660fe54c146 (patch)
treedc2c3b8f51009a96c9be7cd5831e8ce3280caa6b /shared/src/test/scala/ProductTypeFormatTests.scala
parent9545fe93dfe68974ca4bf2f9e6310216fc914e15 (diff)
downloadspray-json-derivation-c4dd18f810afdb4adb85d002ad34e660fe54c146.tar.gz
spray-json-derivation-c4dd18f810afdb4adb85d002ad34e660fe54c146.tar.bz2
spray-json-derivation-c4dd18f810afdb4adb85d002ad34e660fe54c146.zip
Fix bug in derivation of classes with type parametersv0.4.6
Diffstat (limited to 'shared/src/test/scala/ProductTypeFormatTests.scala')
-rw-r--r--shared/src/test/scala/ProductTypeFormatTests.scala24
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}"""
+ )
+
}