From c4aa3c08bcd68339caec30bac8733bf4b653e209 Mon Sep 17 00:00:00 2001 From: Paul Daniels Date: Mon, 5 Dec 2022 17:03:55 +0800 Subject: [PATCH] Fix json generic record decoding (#453) --- .../src/main/scala/zio/schema/codec/JsonCodec.scala | 1 + .../test/scala-2/zio/schema/codec/JsonCodecSpec.scala | 9 +++++++++ 2 files changed, 10 insertions(+) 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 3d862f943..caceb3d16 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 @@ -515,6 +515,7 @@ object JsonCodec { val value = schemaDecoder(schema).unsafeDecode(trace_, in) builder += ((JsonFieldDecoder.string.unsafeDecodeField(trace_, label), value)) case None => + Lexer.char(trace, in, ':') Lexer.skipValue(trace, in) } 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 5abc56c5b..72ecbf6f1 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 @@ -186,6 +186,15 @@ object JsonCodecSpec extends ZIOSpecDefault { } ) ), + suite("generic record")( + test("with extra fields") { + assertDecodes( + recordSchema, + ListMap[String, Any]("foo" -> "s", "bar" -> 1), + charSequenceToByteChunk("""{"foo":"s","bar":1,"baz":2}""") + ) + } + ), suite("transform")( test("string") { val stringSchema = Schema.Primitive(StandardType.StringType)