diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-09-11 17:47:44 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-09-11 17:51:11 -0700 |
commit | 2a372d47b4000f487080b3eeeacd58ba2dfbceea (patch) | |
tree | 249302af8c7b007923dba365c089978f0559ca87 /shared/src/test/scala/OptionFieldTests.scala | |
parent | 4a65471458833f440dc080ddcabf24ed59bd49e1 (diff) | |
download | spray-json-derivation-2a372d47b4000f487080b3eeeacd58ba2dfbceea.tar.gz spray-json-derivation-2a372d47b4000f487080b3eeeacd58ba2dfbceea.tar.bz2 spray-json-derivation-2a372d47b4000f487080b3eeeacd58ba2dfbceea.zip |
Upgrade magnolia
Diffstat (limited to 'shared/src/test/scala/OptionFieldTests.scala')
-rw-r--r-- | shared/src/test/scala/OptionFieldTests.scala | 24 |
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}}""" + ) + } |