zio / zio-schema

Compositional, type-safe schema definitions, which enable auto-derivation of codecs and migrations.
https://zio.dev/zio-schema
Apache License 2.0
142 stars 162 forks source link

Fix JSON decoding of empty objects #710

Closed guersam closed 4 months ago

guersam commented 4 months ago

This PR fixes the decoding failure of discriminated case objects.

Example

@discriminatorName("type")
enum Foo derives Schema:
  case Bar(b: Int)
  case Baz

JsonCodec.jsonDecoder(Schema[Foo]).decodeJson("""{ "type": "Baz" }""")

It also makes case object decoding respect @rejectExtraFields.

However, currently @rejectExtraFields can be applied only to the leaf nodes of ADTs, not the sealed trait/enum itself. To fix this, we need to propagate the parent schema to every caseClassN decoder, but it's out of the scope of this PR. (#700)

/claim #711

guersam commented 3 months ago

/claim #711

@jdegoes Can I claim a bounty with a PR merged in advance?

987Nabil commented 3 months ago

@guersam ask algora ppl in the discord