Hyperledger Fabic 2.2.0 错误处理成功响应。值与架构不匹配

Hyperledger Fabic 2.2.0 Error handling success response. Value did not match schema

我正在使用 Hyperledger Fabric 2.2.0 和 fabric-network 2.1(不那么重要)。

我的链代码是用 Go 编写的。所以我有一些在 JSON 标签中有 ,omitempty 的结构。这是我的结构:

type LeaseDetails struct {
    EndOfTerm string `json:"endOfTerm"`
    Info      string `json:"info,omitempty"`
    Option    string `json:"option,omitempty"`
}

但是我从我的链代码中收到以下错误作为 return 值:

peer=peer0.org1.example.com:7051, status=500, message=Error handling success response. Value did not match schema:
1. return.0.leaseDetails: info,omitempty is required
2. return.0.leaseDetails: option,omitempty is required

如果我从我的结构中删除 ,omitempty,并提供默认值,一切正常。 在 fabric-contract-api-go 的文档中提到有某种序列化程序建立在 json marshal/unmarshal 之上,但对我来说它似乎没有检测到 ,omitempty 关键字。

这是故意的吗?或者我在这里遗漏了什么?

提前致谢

我从用户@awjh 那里得到了关于 Hyperledger Chat 的答案。

This is as intended, the json is compared against the metadata schema. By default all fields are required, using omitempty will mean that the JSON process will remove that field when it has no value. This means a required field will be missing. To fix this add a metadata tag to mark the field as optional metadata:",optional"

所以就我而言,解决方案是:

type LeaseDetails struct {
    EndOfTerm string `json:"endOfTerm"`
    Info      string `json:"info,omitempty" metadata:",optional"`
    Option    string `json:"option,omitempty" metadata:",optional"`
}