已遵循需要json序列化程序的集合column tutorial for phantom-dsl。JSON序列化程序與幻影dsl上的json4s集合列
下面的實現獲取以下錯誤輸出;
發現:org.dyne.danielsan.superchain.data.models.JsonVin
[錯誤]需要:org.json4s.JValue
[誤差(其擴展到)org.json4s .JsonAST.JValue
[錯誤]緊湊的(渲染(OBJ))
在指出我要去的地方錯了,非常感謝任何幫助。問題是,據我所知幻像DSL需要定義自定義類型,但json4s期待一個JValue ...
import com.websudos.phantom.CassandraTable
import com.websudos.phantom.dsl._
import org.json4s.{NoTypeHints, _}
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.Serialization
case class Transaction(blockhash: String,
blocktime: Long,
confirmations: Int,
vout: List[Vout],
vin: List[Vin])
case class JsonVout(value: String,
n: String,
scriptPubKey: String)
case class JsonVin(coinbase: String,
sequence: String)
sealed class TransactionColumnFamily extends CassandraTable[TransactionColumnFamily, Transaction] {
implicit val formats = Serialization.formats(NoTypeHints)
override def fromRow(row: Row): Transaction = {
Transaction(
blockhash(row),
blocktime(row),
confirmations(row),
vout(row),
vin(row)
)
}
object blockhash extends StringColumn(this) with PartitionKey[String]
object blocktime extends LongColumn(this) with ClusteringOrder[Long] with Descending
object confirmations extends IntColumn(this) with ClusteringOrder[Int] with Descending
object vout extends JsonListColumn[TransactionColumnFamily, Transaction, Vout](this) {
override def fromJson(obj: String): Vout = {
parse(obj).extract[Vout]
}
//This is where the first error arises
override def toJson(obj: Vout): String = {
compact(render(obj))
}
}
object vin extends JsonListColumn[TransactionColumnFamily, Transaction, Vin](this) {
override def fromJson(obj: String): Vin = {
parse(obj).extract[Vin]
}
//This is where the second error arises
override def toJson(obj: JsonVin): String = {
compact(render(obj))
}
}
}
object TransactionColumnFamily extends TransactionColumnFamily with RootConnector {
// some more stuff
// some more stuff
}
修正:
感謝弗拉維的評論。你是對的。到底這是需要與Json4s工作內容:
object vout extends JsonListColumn[TransactionColumnFamily, Transaction, Vout](this) {
override def fromJson(obj: String): Vout = {
parse(obj).extract[Vout]
}
override def toJson(obj: Vout): String = {
write(obj)
}
}
object vin extends JsonListColumn[TransactionColumnFamily, Transaction, Vin](this) {
override def fromJson(obj: String): Vin = {
parse(obj).extract[Vin]
}
override def toJson(obj: Vin): String = {
write(obj)
}
}