From ce8cca1a137db61cf1ecea9a66a900795bdc34e6 Mon Sep 17 00:00:00 2001 From: Nabil Abdel-Hafeez <7283535+987Nabil@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:21:27 +0200 Subject: [PATCH] Don't write null for empty option fields of generic records (#728) --- .../shared/src/main/scala/zio/schema/codec/JsonCodec.scala | 1 + .../shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala b/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala index 93e9113ac..9eecca635 100644 --- a/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala +++ b/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala @@ -945,6 +945,7 @@ object JsonCodec { val isEmptyCollection = value match { case _: Iterable[_] => value.asInstanceOf[Iterable[_]].isEmpty + case None => true case _ => false } diff --git a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala index c5222c89a..7bdeabc08 100644 --- a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala +++ b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala @@ -423,7 +423,7 @@ object JsonCodecSpec extends ZIOSpecDefault { RecordExample.schema.annotate(rejectExtraFields()), RecordExample(f1 = Some("test"), f3 = Some("transient")), charSequenceToByteChunk( - """{"$f1":"test","f2":null,"f4":null,"f5":null,"f6":null,"f7":null,"f8":null,"f9":null,"f10":null,"f11":null,"f12":null,"f13":null,"f14":null,"f15":null,"f16":null,"f17":null,"f18":null,"f19":null,"f20":null,"f21":null,"f22":null,"$f23":null}""".stripMargin + """{"$f1":"test"}""".stripMargin ) ) }