aboutsummaryrefslogtreecommitdiff
path: root/shared/src/test/scala/OptionFieldTests.scala
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/test/scala/OptionFieldTests.scala')
-rw-r--r--shared/src/test/scala/OptionFieldTests.scala24
1 files changed, 23 insertions, 1 deletions
diff --git a/shared/src/test/scala/OptionFieldTests.scala b/shared/src/test/scala/OptionFieldTests.scala
index 8cabf25..ac925d7 100644
--- a/shared/src/test/scala/OptionFieldTests.scala
+++ b/shared/src/test/scala/OptionFieldTests.scala
@@ -6,7 +6,8 @@ class OptionFieldTests
extends FlatSpec
with FormatTests {
- case class Opt(x: Option[Int])
+ sealed trait Super
+ case class Opt(x: Option[Int]) extends Super
object HideNull extends DerivedJsonProtocol {
override def printNull = false
@@ -49,5 +50,26 @@ class OptionFieldTests
assert("{}".parseJson.convertTo[Opt] == Opt(None))
}
+ {
+ import ShowNull._
+ implicit val superFmt = jsonFormat[Super]
+ "Option fields of ADTs" should behave like checkRoundtrip(
+ Opt(Some(2)): Super,
+ """{ "@type": "Opt", "x":2}"""
+ )
+ }
+
+ sealed trait Enum
+ case class Value(x: Int) extends Enum
+ case class Wrapper(enum: Option[Enum])
+
+ import ShowNull._
+ implicit val enumFormat: RootJsonFormat[Enum] = jsonFormat[Enum]
+ implicit val superFmt: RootJsonFormat[Wrapper] = jsonFormat[Wrapper]
+ "Option fields of inner ADTs" should behave like checkRoundtrip(
+ Wrapper(Some(Value(1))),
+ """{"enum":{"@type":"Value", "x": 1}}"""
+ )
+
}