diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-08-02 15:24:52 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-08-02 16:04:39 -0700 |
commit | 20afa757f499688b56cbd6b8571014b75d6d4dce (patch) | |
tree | 01d763e6db42e525eb71960519f5098170be9042 /shared/src/test/scala/ProductTypeFormatTests.scala | |
parent | a511ec9662508f72f8ed63b08ccad41647fad9c5 (diff) | |
download | spray-json-derivation-20afa757f499688b56cbd6b8571014b75d6d4dce.tar.gz spray-json-derivation-20afa757f499688b56cbd6b8571014b75d6d4dce.tar.bz2 spray-json-derivation-20afa757f499688b56cbd6b8571014b75d6d4dce.zip |
Treat value classes transparently
Diffstat (limited to 'shared/src/test/scala/ProductTypeFormatTests.scala')
-rw-r--r-- | shared/src/test/scala/ProductTypeFormatTests.scala | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/shared/src/test/scala/ProductTypeFormatTests.scala b/shared/src/test/scala/ProductTypeFormatTests.scala index a869ac5..d7721ba 100644 --- a/shared/src/test/scala/ProductTypeFormatTests.scala +++ b/shared/src/test/scala/ProductTypeFormatTests.scala @@ -90,11 +90,35 @@ class ProductTypeFormatTests case class Phantom[T](x: Int) // no json format required for T - implicit def phantom[T] = jsonFormat[Phantom[T]] + implicit def phantom[T]: RootJsonFormat[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}""" ) + implicit val vc = jsonFormat[ProductTypeFormatTests.Wrapper] + "Value classes" should behave like checkRoundtrip( + ProductTypeFormatTests.Wrapper(42), + """42""" + ) + + implicit def vcg[T: JsonFormat] = jsonFormat[ProductTypeFormatTests.WrapperGeneric[T]] + "Value classes with generic parameters" should behave like checkRoundtrip( + ProductTypeFormatTests.WrapperGeneric[F](F(42)), + """{"y": 42}""" + ) + + implicit def vcp[T] = jsonFormat[ProductTypeFormatTests.WrapperPhantom[T]] + "value classes with unused generic parameters" should behave like checkRoundtrip( + ProductTypeFormatTests.WrapperPhantom[Int => String](42), + """42""" + ) + +} + +object ProductTypeFormatTests { + case class Wrapper(x: Int) extends AnyVal + case class WrapperGeneric[A](x: A) extends AnyVal + case class WrapperPhantom[A](x: Int) extends AnyVal } |