diff --git a/README.md b/README.md index e5e3383f3..8d29f4a3a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [ZIO Schema](https://github.com/zio/zio-schema) is a [ZIO](https://zio.dev)-based library for modeling the schema of data structures as first-class values. -[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-schema/workflows/CI/badge.svg) [![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-schema_2.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-schema_2.13/) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-schema_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-schema_2.13/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-schema-docs_2.13/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-schema-docs_2.13) [![ZIO Schema](https://img.shields.io/github/stars/zio/zio-schema?style=social)](https://github.com/zio/zio-schema) +[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-schema/workflows/CI/badge.svg) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-schema_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-schema_2.13/) [![ZIO Schema](https://img.shields.io/github/stars/zio/zio-schema?style=social)](https://github.com/zio/zio-schema) ## Introduction @@ -39,6 +39,7 @@ _ZIO Schema_ is used by a growing number of ZIO libraries, including [ZIO Flow]( In order to use this library, we need to add the following lines in our `build.sbt` file: ```scala + libraryDependencies += "dev.zio" %% "zio-schema" % "1.1.1" libraryDependencies += "dev.zio" %% "zio-schema-avro" % "1.1.1" libraryDependencies += "dev.zio" %% "zio-schema-bson" % "1.1.1" 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 5c28e7a2c..f56b99605 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 @@ -519,6 +519,7 @@ object JsonCodec { if (emptyObjectDecoder.unsafeDecode(trace, in2)) { None } else { + in2.retract() in2.rewind() zio.json.JsonDecoder.option(A).unsafeDecode(trace, in2) } 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 dd33e8ccf..a52f0bacc 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 @@ -561,6 +561,20 @@ object JsonCodecSpec extends ZIOSpecDefault { charSequenceToByteChunk("""{"a":"s","b":null}""") ) }, + test("case class with int option field present (at end) from pretty printed json") { + assertDecodes( + WithOptionFields.schema, + WithOptionFields(Some("s"), Some(1)), + charSequenceToByteChunk( + """ + |{ + | "a": "s", + | "b": 1 + |} + |""".stripMargin + ) + ) + }, test("case class with option fields omitted when empty") { assertDecodes( WithOptionFields.schema,