Generic derivation for ADTs in Scala with a custom representation
问题 I'm paraphrasing a question from the circe Gitter channel here. Suppose I've got a Scala sealed trait hierarchy (or ADT) like this: sealed trait Item case class Cake(flavor: String, height: Int) extends Item case class Hat(shape: String, material: String, color: String) extends Item …and I want to be able to map back and forth between this ADT and a JSON representation like the following: { "tag": "Cake", "contents": ["cherry", 100] } { "tag": "Hat", "contents": ["cowboy", "felt", "black"] }