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

JSONCodec.decoder streaming is broken with optional values #685

Closed
paulpdaniels opened this issue May 28, 2024 · 5 comments · Fixed by #689
Closed

JSONCodec.decoder streaming is broken with optional values #685

paulpdaniels opened this issue May 28, 2024 · 5 comments · Fixed by #689

Comments

@paulpdaniels
Copy link
Contributor

The latest release (1.2.0) breaks the JsonDecoder[A].decodeJsonPipeline operation in cases where there is an optional primitive within an object body.

Consider:

case class Simple(name: Option[String])
implicit val schema: Schema[Simple] = DeriveSchema.gen

ZStream
  .fromChunk(charSequenceToByteChunk("[{\"name\":\"John\"}]"))
  .via(ZPipeline.decodeCharsWith(StandardCharsets.UTF_8))
  .via(JsonCodec.jsonDecoder(Simple.schema).decodeJsonPipeline(JsonStreamDelimiter.Array))
  .runCollect
  .either
  .map(results => assertTrue(results.isRight))

This results in the error Left(value = java.lang.Exception: .name(expected '"' got 'J')). The same error does not occur when the value is required or if you use the assertDecodes utility in the test project, which is backed by JsonCodec.schemaBasedBinaryCodec[A](cfg)(schema).streamDecoder.

@jdegoes
Copy link
Member

jdegoes commented Jun 8, 2024

/bounty $75

Copy link

algora-pbc bot commented Jun 8, 2024

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #685 with your implementation plan
  2. Submit work: Create a pull request including /claim #685 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-schema!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @paulpdaniels Jun 9, 2024, 3:27:19 AM #689

@paulpdaniels
Copy link
Contributor Author

paulpdaniels commented Jun 9, 2024

/attempt #685

Copy link

algora-pbc bot commented Jun 9, 2024

💡 @paulpdaniels submitted a pull request that claims the bounty. You can visit your bounty board to reward.

Copy link

algora-pbc bot commented Jun 9, 2024

🎉🎈 @paulpdaniels has been awarded $75! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants