Corda 类没有注释或不在白名单上,因此不能在序列化中使用

Corda 类没有注释或不在白名单上,因此不能在序列化中使用,corda,Corda,在Corda中,我定义了以下流程: object Flow { @InitiatingFlow @StartableByRPC class Initiator(val otherParty: Party) : FlowLogic<Unit>() { override val progressTracker = ProgressTracker() @Suspendable override fun call()

在Corda中,我定义了以下流程:

object Flow {
    @InitiatingFlow
    @StartableByRPC
    class Initiator(val otherParty: Party) : FlowLogic<Unit>() {
        override val progressTracker = ProgressTracker()

        @Suspendable
        override fun call() {
            val otherPartyFlow = initiateFlow(otherParty)
            otherPartyFlow.send(MyClass())
        }
    }

    @InitiatedBy(Initiator::class)
    class Acceptor(val otherPartyFlow: FlowSession) : FlowLogic<Unit>() {
        @Suspendable
        override fun call() {
            val unregisteredClassInstance = otherPartyFlow.receive<MyClass>()
        }
    }
}
对象流{
@启动流
@星表
类启动器(val otherParty:Party):FlowLogic(){
重写val progressTracker=progressTracker()
@暂停
覆盖有趣的调用(){
val otherPartyFlow=initiateFlow(otherParty)
otherPartyFlow.send(MyClass())
}
}
@发起人(发起人::类)
类接受程序(val otherPartyFlow:FlowSession):FlowLogic(){
@暂停
覆盖有趣的调用(){
val unregisteredClassInstance=otherPartyFlow.receive()
}
}
}
但是,当我尝试运行流时,会出现以下错误:

类com.example.flow.MyClass未注释或未在白名单上, 因此不能在序列化中使用


如何对类进行注释或将其列入白名单,以允许在流中发送该类?为什么需要这样做?

默认情况下,出于安全目的,只有流中或RPC上存在的类才能发送

有两种方法可以将特定类添加到序列化白名单:

1。将类注释为@cordaseriable:

@CordaSerializable
class MyClass
2。创建序列化白名单插件:

@CordaSerializable
class MyClass
定义序列化插件,如下所示:

class TemplateSerializationWhitelist : SerializationWhitelist {
    override val whitelist: List<Class<*>> = listOf(MyClass::class.java)
}
class TemplateSerializationWhitelist:SerializationWhitelist{
重写val白名单:List=listOf(MyClass::class.java)
}
然后在CorDapp的
src/main/resources/META-INF/services
文件夹中的
net.corda.core.serialization.serialization.SerializationWhitelist
文件中列出序列化白名单插件的完全限定类名(例如
com.example.TemplateSerializationWhitelist

为什么有两种方法可以将类添加到序列化白名单?


第一种方法比较简单,但当您无法将注释添加到要发送的类时,则不可能使用第一种方法。

默认情况下,出于安全目的,只能在流内或通过RPC发送上存在的类

有两种方法可以将特定类添加到序列化白名单:

1.将类注释为@cordaseriable:

@CordaSerializable
class MyClass
2.创建序列化白名单插件:

@CordaSerializable
class MyClass
定义序列化插件,如下所示:

class TemplateSerializationWhitelist : SerializationWhitelist {
    override val whitelist: List<Class<*>> = listOf(MyClass::class.java)
}
class TemplateSerializationWhitelist:SerializationWhitelist{
重写val白名单:List=listOf(MyClass::class.java)
}
然后在CorDapp的
src/main/resources/META-INF/services
文件夹中的
net.corda.core.serialization.serialization.SerializationWhitelist
文件中列出序列化白名单插件的完全限定类名(例如
com.example.TemplateSerializationWhitelist

为什么有两种方法可以将类添加到序列化白名单?


第一种方法比较简单,但当您无法将注释添加到要发送的类时,则不可能使用该方法。

生成是否通过扫描类以获取序列化白名单的实现来自动生成该文件?生成是否通过扫描类以获取序列化白名单的实现来自动生成该文件白名单?