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

Strange handling of empty json array (possibly zio-schema bug?) #3186

Open
russwyte opened this issue Oct 2, 2024 · 4 comments
Open

Strange handling of empty json array (possibly zio-schema bug?) #3186

russwyte opened this issue Oct 2, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@russwyte
Copy link
Contributor

russwyte commented Oct 2, 2024

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?

@russwyte russwyte added the bug Something isn't working label Oct 2, 2024
@russwyte
Copy link
Contributor Author

russwyte commented Oct 2, 2024

This is the issue. It seems like the default should be false - as empty collections are valid data.

@russwyte
Copy link
Contributor Author

russwyte commented Oct 2, 2024

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))

@jdegoes
Copy link
Member

jdegoes commented Nov 9, 2024

@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).

@987Nabil
Copy link
Contributor

987Nabil commented Nov 9, 2024

Yeah. I think we should

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants