Scala类型差异使用json4s在phantom-dsl中使用JSON序列化程序时出错

时间:2016-05-20 03:48:05

标签: scala json4s phantom-dsl

以下代码出现以下错误。任何见解都非常感谢。不太确定导致这种情况的原因是因为我在整个应用程序中有足够的其他用户定义类型而没有引起这种行为。

如果需要更多信息以便能够提供指导/建议,请与我们联系。

    [error] /Users/dan_mi_sun/projects/openblockchain/src/main/scala/org/dyne/danielsan/openblockchain/data/model/GenericVinModel.scala:35: type mismatch;
    [error]  found   : org.dyne.danielsan.openblockchain.data.model.VinsModel
    [error]  required: com.websudos.phantom.CassandraTable[org.dyne.danielsan.openblockchain.data.model.VinsModel,org.dyne.danielsan.openblockchain.data.entity.Vin]
    [error] Note: org.dyne.danielsan.openblockchain.data.model.ConcreteVinsModel <: org.dyne.danielsan.openblockchain.data.model.VinsModel (and org.dyne.danielsan.openblockchain.data.model.VinsModel <: com.websudos.phantom.CassandraTable[org.dyne.danielsan.openblockchain.data.model.ConcreteVinsModel,org.dyne.danielsan.openblockchain.data.entity.Vin]), but class CassandraTable is invariant in type T.
    [error] You may wish to define T as +T instead. (SLS 4.5)
    [error]   object scriptsig extends JsonListColumn[VinsModel, Vin, ScriptSig](this) {
    [error]                                                                      ^
    [error] one error found
import com.websudos.phantom.CassandraTable
import com.websudos.phantom.dsl._
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.write

import scala.concurrent.Future

case class ScriptSig(asm: String,
                     hex: String)

case class Vin(txid: String,
               vout: Int,
               scriptSig: List[ScriptSig],
               sequence: Int)

sealed class VinsModel extends CassandraTable[ConcreteVinsModel, Vin] {

  implicit val formats = Serialization.formats(NoTypeHints)

  override def fromRow(row: Row): Vin = {
    Vin(
      txid(row),
      vout(row),
      scriptSig(row),
      sequence(row)
    )
  }

  object txid extends StringColumn(this)

  object vout extends IntColumn(this)

  object scriptSig extends JsonListColumn[VinsModel, Vin, ScriptSig](this) {
    override def fromJson(obj: String): ScriptSig = {
      parse(obj).extract[ScriptSig]
    }

    override def toJson(obj: ScriptSig): String = {
      write(obj)
    }

  }

  object sequence extends IntColumn(this)
}

abstract class ConcreteVinsModel  extends VinsModel  with RootConnector {

  override val tableName = "vins"

  def insertNew(v: Vin): Future[ResultSet] = insertNewVin(v).future()

  def insertNewVin(v: Vin) = {
    insert
      .value(_.txid, v.txid)
      .value(_.vout, v.vout)
      .value(_.scriptSig, v.scriptSig)
      .value(_.sequence, v.sequence)
  }
}

1 个答案:

答案 0 :(得分:0)

这一行:

object scriptSig extends JsonListColumn[VinsModel, Vin, ScriptSig](this)

应该是

object scriptSig extends JsonListColumn[ConcreteVinsModel, Vin, ScriptSig](this)