是否可以反序列化以下JSON
{
"operation": "create", // type discriminator
"value": "some text",
"source": {
"name": "source name",
"kind": "db" // type discriminator
}
}
进入以下一组课程
sealed trait Source
case class DbSource(name: String) extends Source
sealed trait Operation
case class CreateOperation(value: String, source: Source) extends Operation
使用Json4s而不求助于自定义反序列化器吗?
答案 0 :(得分:0)
Json库Circe提供了您所需要的东西:The relevant page
implicit val sourceConfig: Configuration =
Configuration.default.withDiscriminator("operation")
答案 1 :(得分:0)
不了解json4s,不过您可以使用jackson来做到这一点: http://chromedriver.chromium.org/downloads