我想在Corda中运行汽车保险项目,但我不知道如何在对象类型中传递ClaimInfo数据,任何人都可以帮助我
https://github.com/corda/samples/tree/release-V4/carinsurance-QueryableState
我正在尝试像这样传递数据
start InsuranceClaimInitiator claimInfo: {claimNumber: "aa",claimDescription: "rrrr", claimAmount: 9}, policyNumber: "aaa"
这是对的还是我们应该通过不同的方式?
它向我显示此错误
Wed Feb 19 16:34:55 IST 2020>>> flow start InsuranceClaimFlow$InsuranceClaimInitiator claimInfo: {claimNmuber: "c001",claimDescription: "hello",claimAmount: 123}, policyNumber: "hello"
No matching constructor found:
- [class net.corda.examples.carinsurance.flows.ClaimInfo, class java.lang.String]: Could not parse as a command: Cannot construct instance of `net.corda.examples.carinsurance.flows.ClaimInfo` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; line: -1, column: -1]
Wed Feb 19 16:35:16 IST 2020>>> flow start InsuranceClaimFlow$InsuranceClaimInitiator {claimInfo: {claimNmuber: "c001",claimDescription: "hello",claimAmount: 123}}, policyNumber: "hello"
flow start InsuranceClaimFlow$InsuranceClaimInitiator {claimInfo: {claimNmuber: "c001",claimDescription: "hello",claimAmount: 123}}, policyNumber: "hello": exception: Expected a field name (Scalar value in YAML), got this instead: <org.yaml.snakeyaml.events.MappingStartEvent(anchor=null, tag=null, implicit=true)>
at [Source: (StringReader); line: 1, column: 4]
Wed Feb 19 16:36:00 IST 2020>>> [ERROR] 16:36:00+0530 [pool-8-thread-5] command.CRaSHSession. - Error while evaluating request 'flow start InsuranceClaimFlow$InsuranceClaimInitiator {claimInfo: {claimNmuber: "c001",claimDescription: "hello",claimAmount: 123}}, policyNumber: "hello"' flow start InsuranceClaimFlow$InsuranceClaimInitiator {claimInfo: {claimNmuber: "c001",claimDescription: "hello",claimAmount: 123}}, policyNumber: "hello": exception: Expected a field name (Scalar value in YAML), got this instead: <org.yaml.snakeyaml.events.MappingStartEvent(anchor=null, tag=null, implicit=true)>
at [Source: (StringReader); line: 1, column: 4] [errorCode=rc1dem, moreInformationAt=https://errors.corda.net/OS/4.3/rc1dem]
向ClaimInfo添加一个默认构造函数,它应该可以正常工作。还要用@ConstructorForDeserialization标记参数化的构造函数。它需要默认的构造函数来反序列化。
public ClaimInfo(){
this.claimNumber = null;
this.claimDescription = null;
this.claimAmount = 0;
}
@ConstructorForDeserialization
public ClaimInfo(String claimNumber, String claimDescription, int claimAmount) {
this.claimNumber = claimNumber;
this.claimDescription = claimDescription;
this.claimAmount = claimAmount;
}
我认为我们应该在样本中对此进行更新,或者如果您愿意,最好可以进行PR。
我仍然遇到相同的错误
我注意到您有一个错字“ claimNmuber”。你纠正了吗?
是的,我已经纠正了错别字,但仍然存在相同的错误,任何人都可以在项目结束时运行该项目,并查看其是否正常运行。
因此添加默认构造函数后,代码即可正常工作
谢谢大家