Hyperledger Fabic 2.2.0错误处理成功响应.值与架构不符 [英] Hyperledger Fabic 2.2.0 Error handling success response. Value did not match schema

查看:93
本文介绍了Hyperledger Fabic 2.2.0错误处理成功响应.值与架构不符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hyperledger Fabric 2.2.0和Fabric-network 2.1(不是很重要).

I am using Hyperledger Fabric 2.2.0 and fabric-network 2.1 (not that important).

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

My chaincode is written in Go. So I have some structs which have ,omitempty in JSON tag. Here is my struct:

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

但是我从链码中得到以下错误作为返回值:

But I am getting the following error as a return value from my chaincode:

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关键字.

If I remove ,omitempty from my struct, and provide default value everything works fine. In the docs for fabric-contract-api-go it is mentioned that there is some kind of serializer built upon json marshal/unmarshal, but to me it doesn't seem to detect the ,omitempty keyword.

这是故意的吗?还是我在这里想念东西?

Was this intentional? Or am I missing something here?

预先感谢

推荐答案

我在

这符合预期,将json与元数据模式进行比较. 默认情况下,所有字段都是必填字段,使用omitempty表示 如果该字段没有值,则JSON进程将删除该字段.这意味着 必填字段将丢失.要解决此问题,请添加元数据标记以进行标记 该字段为可选的metadata:",optional"

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"

因此,在我的情况下,解决方案是:

So in my case, the solution is:

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

这篇关于Hyperledger Fabic 2.2.0错误处理成功响应.值与架构不符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆