Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decoding optional integral (Int,Long) at the end of pretty print json. #676

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading