我正在使用Play框架,有一个抽象类:
abstract class Base{...}
伴生对象中有内置的JSON编写程序
object Base {
implicit val baseWrites: Writes[Base] = (...)(unlift(Base.unapply))
}
我继承了这个抽象类:
case class SubClass{...}
该对象还具有其自己的隐式 JSON writer,位于其伴生对象中
object SubClass {
implicit val subClassWrites: Writes[SubClass] = (...)(unlift(SubClass.unapply))
}
当我尝试使用Json.toJson(SubClass)序列化子类对象时,出现错误:
[error] both value subClassWrites in object SubClass of type => play.api.libs.json.
Writes[models.SubClass]
[error] and value baseWrites in object Base of type =>
play.api.libs.json.Writes[models.Base]
[error] match expected type play.api.libs.json.Writes[models.SubClass]
[error] Ok(Json.toJson(SubClass.find(id)))
有没有办法消除歧义?