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 · 2 comments
Open

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

russwyte opened this issue Oct 2, 2024 · 2 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))

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

1 participant