Skip to content

Commit

Permalink
Fix decoding optional integral (Int,Long) at the end of pretty print …
Browse files Browse the repository at this point in the history
…json. (#676)

* make tests pass

* generate readme

---------

Co-authored-by: Milad Khajavi <[email protected]>
  • Loading branch information
russwyte and khajavi authored May 17, 2024
1 parent 9d7150b commit ab46e4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ab46e4d

Please sign in to comment.