For the case classes, you also need to override fromProduct
, right? It could look something like this
object Person:
@synthetic
def fromProduct(p: Product): Person = p.productArity match
case 2 =>
Person(
p.productElement(0).asInstanceOf[String],
p.productElement(1).asInstanceOf[String],
)
case 3 =>
Person(
p.productElement(0).asInstanceOf[String],
p.productElement(1).asInstanceOf[String],
p.productElement(2).asInstanceOf[String],
)
case 4 =>
Person(
p.productElement(0).asInstanceOf[String],
p.productElement(1).asInstanceOf[String],
p.productElement(2).asInstanceOf[String],
p.productElement(3).asInstanceOf[Option[String]],
)
Shout out to @armanbilge who discovered this