From 83942244b48d8f7a68ecdaade90b92a79378d43c Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Thu, 29 Mar 2018 13:11:43 -0700 Subject: Allow deserialization of option fields if they are omitted Fixes #5 --- shared/src/test/scala/ProductTypeFormatTests.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'shared/src/test/scala/ProductTypeFormatTests.scala') 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)) + } + } -- cgit v1.2.3