Problem
derives JsonReader and derives Encoder on Scala 3 enums with parameterized cases fails with a macro expansion error:
enum Endpoint derives JsonReader, Encoder:
case HttpIngress(host: String, port: Int)
case NodePort(port: Int, protocol: String)
Error:
Exception occurred while executing macro expansion.
scala.MatchError: ... (of class scala.quoted.runtime.impl.ExprImpl)
at besom.json.ProductFormatsMacro$.jsonReaderImpl(ProductFormats.scala:177)
Current Workaround
Using sealed trait + case classes instead:
sealed trait Endpoint
object Endpoint:
case class HttpIngress(...) extends Endpoint derives JsonReader, Encoder
case class NodePort(...) extends Endpoint derives JsonReader, Encoder
Expected
Enum with case class variants should work with derives JsonReader, Encoder, producing a discriminated union JSON representation.
Problem
derives JsonReaderandderives Encoderon Scala 3 enums with parameterized cases fails with a macro expansion error:Error:
Current Workaround
Using sealed trait + case classes instead:
Expected
Enum with case class variants should work with
derives JsonReader, Encoder, producing a discriminated union JSON representation.