From 2a372d47b4000f487080b3eeeacd58ba2dfbceea Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Tue, 11 Sep 2018 17:47:44 -0700 Subject: Upgrade magnolia --- shared/src/test/scala/OptionFieldTests.scala | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'shared/src/test/scala/OptionFieldTests.scala') 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}}""" + ) + } -- cgit v1.2.3