zio / zio-json

Fast, secure JSON library with tight ZIO integration.
https://zio.dev/zio-json
Apache License 2.0
401 stars 143 forks source link

feat: implement Scala 3 Constant and Union support for string-based literals as enums #1125

Closed ThijsBroersen closed 3 weeks ago

ThijsBroersen commented 3 weeks ago

This PR implements support for string-based literal types. Single-value or Union-based.

Example:

case class Foo(aOrB: "A" | "B", optA: Option["A"]) derives JsonCodec

Foo("A", Some("A")).toJson

"""{"aOrB": "A", "optA": "A"}""".fromJson[Foo]
ThijsBroersen commented 3 weeks ago

I have a commit with doc changes ready but mdoc is not configured for Scala 3 examples... Can we change that?