Strange handling of empty json array (possibly zio-schema bug?)
Describe the bug Routes that produce JSON don't correctly handle empty collections. The resulting JSON should always have a field with an empty JSON array - but instead the field is omitted altogether. To Reproduce See this gist result of run is:
unexpected: {"bars":[1,2,3]}
expected: {"bars":[1,2,3]}
unexpected: {}
expected: {"bars":[]}
Additional context This causes breakage in codecs when lists are not optional and are empty
The gist also shows a work-around that might shed light on a possible fix?
This is the issue. It seems like the default should be false - as empty collections are valid data.
Adding this works - but this seems like it should be the default as it is in zio-json and elsewhere
val routes = Routes(
unexpected.implement(foo => ZIO.succeed(foo)),
expected.implement(foo => ZIO.succeed(foo))
) @@ CodecConfig.withConfig(CodecConfig(ignoreEmptyCollections = false))
@987Nabil Should we change the default here? I too would expect empty collections to be represented in responses (but missing collections to be accepted in requests -- notice the duality).
Yeah. I think we should
Just got bitten by it. It's indeed quite unexpected.
/bounty $100
💎 $100 bounty • ZIO
Steps to solve:
- Start working: Comment
/attempt #3186with your implementation plan - Submit work: Create a pull request including
/claim #3186in the PR body to claim the bounty - Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts
❗ Important guidelines:
- To claim a bounty, you need to provide a short demo video of your changes in your pull request
- If anything is unclear, ask for clarification before starting as this will help avoid potential rework
- Low quality AI PRs will not receive review and will be closed
- Do not ask to be assigned unless you've contributed before
Thank you for contributing to zio/zio-http!
| Attempt | Started (UTC) | Solution | Actions |
|---|---|---|---|
| 🟢 @987Nabil | May 02, 2025, 08:56:13 AM | #3481 | Reward |
| 🔴 @Ronyonka | Feb 03, 2025, 11:13:14 AM | WIP |
@Ronyonka: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏
Hey, has this been released? Still drops the empty collection field under zio-http 3.2.0.
🎉🎈 @987Nabil has been awarded $100 by ZIO! 🎈🎊