I have some case classes defined like follows:
sealed trait Breed
case object Beagle extends Breed
case object Mastiff extends Breed
case object Yorkie extends Breed
case class Dog(name: String, breed: Breed)
I also have an endpoint defined with Scalatra:
post("/dog") {
val dog = parsedBody.extract[Dog]
...
}
I'd like this JSON object:
{
name: "Spike",
breed: "Mastiff"
}
to deserialize to the appropriate instance of Dog
. I'm struggling to figure out how to write a custom deserializer for Breed
and register it with JSON4S.