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