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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…