Skip to content

Commit

Permalink
Fix pretty printing for JSON encoder of Schema.Fallback (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk authored Jan 11, 2025
1 parent 64fc155 commit 5c1ad8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,10 @@ object JsonCodec {
indent_ = bump(indent)
pad(indent_, out)
}
left.unsafeEncode(a, indent, out)
left.unsafeEncode(a, indent_, out)
out.write(',')
if (doPrettyPrint) pad(indent_, out)
right.unsafeEncode(b, indent, out)
right.unsafeEncode(b, indent_, out)
if (doPrettyPrint) pad(indent, out)
out.write(']')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ object JsonCodecSpec extends ZIOSpecDefault {
Fallback.Both(3, "hello"),
"""[3,"hello"]"""
)
},
test("both pretty printed") {
val json = JsonCodec
.jsonCodec(Schema.Fallback(Schema.set[Int], Schema.chunk[String]))
.encoder
.encodeJson(
Fallback.Both(Set(3), Chunk("hello")),
Some(0)
)
assert(json)(
equalTo(
"""[
| [
| 3
| ],
| [
| "hello"
| ]
|]""".stripMargin
)
)
}
),
suite("optional")(
Expand Down

0 comments on commit 5c1ad8f

Please sign in to comment.