1
我有下面的類結構,包括繼承噴霧JSON序列化繼承案例類
sealed trait GeometryObject
case class Point(coordinates: Array[Double],`type` :GeometryObjectsType) extends GeometryObject
case class Polygon(coordinates: Array[Array[Array[Double]]],`type` :GeometryObjectsType) extends GeometryObject
我的協議如下所示:
object GeoJsonProtocol extends DefaultJsonProtocol {
implicit val geometryObjectsTypeFormat = GeometryObjectsTypeFormat
implicit val polygonFormat = jsonFormat2(Polygon)
implicit val pointFormat = jsonFormat2(Point)
}
得到一個錯誤 - 無法找到證據參數內含價值類型GeometryObject。
有沒有辦法如何處理,並保持繼承的靈活性?
你在哪裏定義GeometryObjectsTypeFormat?擺脫這一行'隱式val geometryObjectsTypeFormat = GeometryObjectsTypeFormat'應該可以解決這個問題。 –
在我的協議中,有層次結構。格式在葉節點處定義。在這種情況下,這是不幸的可能 – jaksky
@AndreasNeumann GeometryObjectsTypeFormat是一種處理類型字段中的各種類型的格式。還有一個層次結構。不要混淆GeometryObjectsTypeFormat和GeometryObjectsFormat – jaksky