diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-03-29 13:11:43 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-03-29 13:21:06 -0700 |
commit | 3a1d922d817fe570a34ce94bf5ec3214369d5af8 (patch) | |
tree | ba0ef59971c29af862ee04e283fb89949b563c61 /src/test/scala/ProductTypeFormatTests.scala | |
parent | 2f3f9aa851080b6c79f3af14b3fdfeab56feffec (diff) | |
download | spray-json-derivation-option.tar.gz spray-json-derivation-option.tar.bz2 spray-json-derivation-option.zip |
Allow deserialization of optional fields if they are omittedoption
Fixes #5
Diffstat (limited to 'src/test/scala/ProductTypeFormatTests.scala')
-rw-r--r-- | src/test/scala/ProductTypeFormatTests.scala | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/scala/ProductTypeFormatTests.scala b/src/test/scala/ProductTypeFormatTests.scala index ce05000..d602ff4 100644 --- a/src/test/scala/ProductTypeFormatTests.scala +++ b/src/test/scala/ProductTypeFormatTests.scala @@ -74,4 +74,21 @@ class ProductTypeFormatTests """{"h": {"x":true}}""" ) + case class Opt(x: Option[Int]) + implicit val ofmt = jsonFormat[Opt] + + "Optional fields with some value" should behave like checkRoundtrip( + Opt(Some(2)), + """{"x":2}""" + ) + + "Optional fields with no value (null)" should behave like checkRoundtrip( + Opt(None), + """{"x":null}""" + ) + + "Optional fields with no value (undefined)" should "deserialize" in { + assert("{}".parseJson.convertTo[Opt] == Opt(None)) + } + } |