我定义了以下接口:
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.cordadeclub.directagreement.contract.directagreementcontract$命令$gotodirect“ ->类com.cordadeclub.directagreement.contract.directagreementcontract$命令$gotodirect at net.corda.nodeapi.internal.serialization.amqp.schema kt.fingerprintformype(schema.kt:438) ~[corda-node-api-3.3-corda.jar:?] at net.corda.nodeapi.internal.serialization.amqp.schema kt.fingerprintfortype$default(schema.kt:352) ~[corda-node-api-3.3-corda.jar:?]
如果我将构造函数中的参数名更改为:
class GoToDirect(bustParty: Party, isBust: Boolean) : IsBustCommand(bustParty, isBust), Commands```
然后我就不再收到例外了。这是怎么回事?
CORDA序列化框架要求每个构造函数参数对应于同名类的属性。
在第一个例子中, party 不是的属性 GoToDirect 或者它的超级类/接口,所以这个条件失败(您可以通过添加 val 致建造商如下: class GoToDirect(val party: Party, isBust: Boolean) )
party
GoToDirect
val
class GoToDirect(val party: Party, isBust: Boolean)
在第二个示例中, bustParty 不是的属性 哥多迪斯特 但是它是 IsBustCommand ,满足了这个条件,序列化成功。
bustParty
哥多迪斯特
IsBustCommand