【问题标题】:In Corda, constructor parameter doesn't refer to a property error在 Corda 中,构造函数参数不引用属性错误
【发布时间】:2018-11-08 16:15:59
【问题描述】:

我定义了如下接口:

open class IsBustCommand(val bustParty: Party, val isBust: Boolean)

还有以下命令:

interface Commands : CommandData {
    class GoToDirect(party: Party, isBust: Boolean) : IsBustCommand(party, isBust), Commands
}

当我运行流程时,它会抛出:

java.io.NotSerializableException: 构造函数参数 - “party” - 不引用“类”的属性 com.cordacodeclub.directAgreement.contract.DirectAgreementContract$Commands$GoToDirect" -> com.cordacodeclub.directAgreement.contract.DirectAgreementContract$Commands$GoToDirect 类 在 net.corda.nodeapi.internal.serialization.amqp.SchemaKt.fingerprintForType(Schema.kt:438) ~[corda-node-api-3.3-corda.jar:?] 在 net.corda.nodeapi.internal.serialization.amqp.SchemaKt.fingerprintForType$default(Schema.kt:352) ~[corda-node-api-3.3-corda.jar:?]

如果我将构造函数中的参数名称更改为:

class GoToDirect(bustParty: Party, isBust: Boolean) : IsBustCommand(bustParty, isBust), Commands```

然后我不再收到异常。这是怎么回事?

【问题讨论】:

    标签: corda


    【解决方案1】:

    Corda 序列化框架要求每个构造函数参数对应一个同名类的属性。

    在第一个示例中,party 不是GoToDirect 或其超类/接口的属性,因此此条件失败(您可以通过向构造函数添加val 来解决此问题,如下所示:@987654324 @)。

    第二个例子中,bustParty不是GoToDirect的属性,而是IsBustCommand的属性,所以满足这个条件,序列化成功。

    【讨论】:

      猜你喜欢
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-06
      • 1970-01-01
      • 2012-03-25
      相关资源
      最近更新 更多