Fields missing even with @Property. Unclear documentation?
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 45/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- java
调研方向
首先阅读 @Property 注解文档,以及报告所确定的相关路径 DataTypeDefinitionImpl 和 JSONTransactionSerializer。明确说明带注解的字段需要 getter 才会出现在返回的 JSON 中,并更新注解文档,使 Sale 示例的预期序列化行为清晰明确。
由索引模型根据 Issue 内容生成。
描述
Steps to reproduce
I'm looking at version 2.3 but I think the behavior holds for the lastest version.
The following code is based on https://github.com/hyperledger/fabric-samples/tree/main/asset-transfer-basic/chaincode-java.
@DataType
public class Sale {
@Property
private String guid = "1";
public Object getPK() {
return guid;
}
}
@Contract
public final class AssetTransfer implements ContractInterface {
@Transaction(intent = Transaction.TYPE.EVALUATE)
public Sale getSale(final Context ctx) {
return new Sale();
}
}
Run the code on the test-network.
What I expect
When I call
peer chaincode query -C mychannel -n basic -c '{"Args":["getSale"]}'
I expect to see a non-empty output. The output might be {guid:"1"} or {PK:"1"}, I don't know.
Since I already used @Property to annotate a field, I do not expect to see an empty json, i.e., {}.
What actually happened
$ peer chaincode query -C mychannel -n basic -c '{"Args":["getSale"]}'
{}
Discussion
I looked into fabric-chaincode-java. The constructor of DataTypeDefinitionImpl puts "guid" to this.properties. Then we execute JSONTransactionSerializer.toBuffer(). We will run final JSONObject obj = new JSONObject(new JSONObject(value), propNames); where propNames is ["guid"]. JSONObject outputs nothing in this situation.
It looks like to me that in order for field X to show up in the returned JSON, we have to 1. add @Property to field X; 2. make sure field X has a getter named getX.
To prove if I change to
@DataType
public class Sale {
@Property
private String guid = "1";
public Object getGuid() {
return guid;
}
}
I get
$ peer chaincode query -C mychannel -n basic -c '{"Args":["getSale"]}'
{"guid":"1"}
Suggestion
I feel this issue could be a documentation oversight as @Property didn't mention getters. If maintainers like, I can add something like
/**
* Field and parameter level annotation defining a property of the class.
*
* When this annotation applied to a field, make sure the field has a
* getter.
...
- 主要语言
- Java
- 星标
- 322
- 派生
- 210
- 平均合并
- 15 小时 16 分钟
- 30 天内合并 PR
- 29
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
hyperledger/fabric-chaincode-java 的其他 Issue
-
enhancement
难度 4/5 3-5 天 新手友好度 48/100
hyperledger/fabric-chaincode-java#628 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
hyperledger/fabric-chaincode-java#627 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 75/100
hyperledger/fabric-chaincode-java#626 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 68/100
hyperledger/fabric-chaincode-java#625 ·
维护者通常 1 天内回复
-
Read/write batching可能重新可做 @jadebluestar 于 119 天前认领,目前没有进行中的 PR。 未关闭enhancement help wanted
难度 4/5 3-5 天 新手友好度 45/100
hyperledger/fabric-chaincode-java#378 · 4 条评论 ·
维护者通常 1 天内回复
查看 hyperledger/fabric-chaincode-java 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
adorsys/keycloak-config-cli#1709 ·
维护者通常 1 天内回复
-
! and-bugs
难度 2/5 1-3 小时 新手友好度 78/100
osmandapp/OsmAnd#26769 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
NationalSecurityAgency/ghidra#9997 · 2 条评论 ·
维护者通常 2 天内回复
-
[Bug] DefaultSerializationExceptionWrapper does not implement Cleanable, so cleanup() is never invoked by codecs可能已有人在做 @binbin0325 今天认领。 未关闭component/need-triage type/need-triage
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
fix: tagged PDF fails with ClassCastException when a Form and its Image share an XObject name可能已有人在做 @hnc-jglee 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
opendataloader-project/opendataloader-pdf#830 ·
维护者通常 1 天内回复