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

feat: allow discriminator to not be the first field #619

Closed runtologist closed 11 months ago

runtologist commented 11 months ago

In the JSON decoder allow enum discriminators to appear in any position in an object, not just the first.

If the discriminator comes first, the behavior is mostly unchanged: We use the discriminator to find the schema of the relevant enum case and continue parsing with this schema. In case the discriminator appears later, it is searched first, then the Lexer is rewound to the beginning of the object, and it is parsed with the schema of the relevant enum case. The discriminator is skipped over in case class parsing.

/fixes #523