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 8c22480fa..fb56ec666 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 @@ -273,6 +273,7 @@ object JsonCodec { case Schema.Primitive(StandardType.StringType, _) => Option(JsonFieldEncoder.string) case Schema.Primitive(StandardType.LongType, _) => Option(JsonFieldEncoder.long) case Schema.Primitive(StandardType.IntType, _) => Option(JsonFieldEncoder.int) + case Schema.Lazy(inner) => jsonFieldEncoder(inner()) case _ => None } @@ -598,6 +599,7 @@ object JsonCodec { case Schema.Primitive(StandardType.StringType, _) => Option(JsonFieldDecoder.string) case Schema.Primitive(StandardType.LongType, _) => Option(JsonFieldDecoder.long) case Schema.Primitive(StandardType.IntType, _) => Option(JsonFieldDecoder.int) + case Schema.Lazy(inner) => jsonFieldDecoder(inner()) case _ => None } diff --git a/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala index d35adb72d..933c6ccb3 100644 --- a/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala +++ b/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala @@ -96,6 +96,15 @@ object JsonCodecSpec extends ZIOSpecDefault { """{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}""" ) ) + }, + test("of simple keys and values where the key's schema is lazy") { + assertEncodes( + Schema.map[Int, Value](Schema.defer(Schema[Int]), Schema[Value]), + Map(0 -> Value(0, true), 1 -> Value(1, false)), + charSequenceToByteChunk( + """{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}""" + ) + ) } ), suite("Set")( @@ -469,6 +478,15 @@ object JsonCodecSpec extends ZIOSpecDefault { """{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}""" ) ) + }, + test("of simple keys and values where the key schema is lazy") { + assertDecodes( + Schema.map[Int, Value](Schema.defer(Schema[Int]), Schema[Value]), + Map(0 -> Value(0, true), 1 -> Value(1, false)), + charSequenceToByteChunk( + """{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}""" + ) + ) } ) )