假设我有一个类层次结构,如:
trait Event
case class ThisEvent extends Event
case class ThatEvent extends Event
case class AnotherEvent extends Event
目前在我的序列化代码中,我必须使用这个:
implicit val formats = new DefaultFormats {
override val typeHintFieldName = "_t"
override val typeHints = ShortTypeHints(List(classOf[ThisEvent], classOf[ThatEvent], classOf[AnotherEvent]))
}
但我非常喜欢这样的东西:
implicit val formats = new DefaultFormats {
override val typeHintFieldName = "_t"
override val typeHints = ShortTypeHints(List(classOf[Event]))
}
你会如何解决这个问题?