Corda 如何将UniqueIdentifier序列化为字符串并返回

Corda 如何将UniqueIdentifier序列化为字符串并返回,corda,Corda,我需要在两个服务之间传递一个UniqueIdentifier。不幸的是UniqueIdentifier#toString和UniqueIdentifier.fromString如果设置了externalId,则无法正常工作 序列化和反序列化UniqueIdentifier的标准方法是什么?等一下,您是否必须为您的某些业务创建UniqueIdentifier?在这种情况下,您可以从头创建一个UniqueIdentifier,并将其作为变量在服务之间传递(事务接受外部附件) 如果你必须“提取”你所在

我需要在两个服务之间传递一个
UniqueIdentifier
。不幸的是
UniqueIdentifier#toString
UniqueIdentifier.fromString
如果设置了
externalId
,则无法正常工作


序列化和反序列化UniqueIdentifier的标准方法是什么?

等一下,您是否必须为您的某些业务创建UniqueIdentifier?在这种情况下,您可以从头创建一个UniqueIdentifier,并将其作为变量在服务之间传递(事务接受外部附件)

如果你必须“提取”你所在州的唯一标识符,我认为这是不可能的


如果我错过了这一点,我提前道歉:D

如果您使用Corda的库创建带有自定义外部id的
唯一标识符集,您可以看到
toString()
将生成
${externalId}\u$id
的模式,即
DummeyexternalId\u 10ed0cc3-7bdf-4000-b610-595e3667d7d

因此,要将其从该字符串转换回UniqueIdentifier,只需通过分隔符
\uuu

if (p.text.contains("_")) {
            val ids = p.text.split("_")
            //Create UUID object from string.
            val uuid: UUID = UUID.fromString(ids[1])
            //Create UniqueIdentifier object using externalId and UUID.
            return UniqueIdentifier(ids[0], uuid)
        }
链接

如果外部id中有下划线,则可能需要自己的函数

val potentialIds = input.split("_")

// Drop last one and stitch back the external id
val externalIdString = potentialIds.dropLast(1).joinToString("_")

// Last one is the UUID
val uuid = UUID.fromString(potentialIds.last())
val finalUniqueIdentifier = UniqueIdentifier(externalIdString, uuid)

UniqueIdentifier已经创建,然后存储在Corda之外,现在我想把它传回。如果你想把数据传回网络,你必须使用Oracles,我想Corda.doc页面上有一些教程谢谢!我想这是官方的说法,但如果外部Id包含下划线,解析器似乎会停止运行。您可能需要一个自定义函数来实现这一点。在答案中加上@Voddan或者更确切地说,Corda需要修复一个bug;)顺便说一句,如果初始UI中没有外部ID,那么第二个实现也会失败。我认为第4行末尾的.ifEmpty{null}应该可以解决这个问题。