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.
@DataTypepublicclassSale {
@PropertyprivateStringguid = "1";
publicObjectgetPK() {
returnguid;
}
}
@ContractpublicfinalclassAssetTransferimplementsContractInterface {
@Transaction(intent = Transaction.TYPE.EVALUATE)
publicSalegetSale(finalContextctx) {
returnnewSale();
}
}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
@DataTypepublicclassSale {
@PropertyprivateStringguid = "1";
publicObjectgetGuid() {
returnguid;
}
}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
/**
* Fieldandparameterlevelannotationdefiningapropertyoftheclass.
* * Whenthisannotationappliedtoafield, makesurethefieldhasa * getter.
...
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.
Run the code on the test-network.
What I expect
When I call
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
@Propertyto annotate a field, I do not expect to see an empty json, i.e.,{}.What actually happened
Discussion
I looked into fabric-chaincode-java. The constructor of DataTypeDefinitionImpl puts "guid" to
this.properties. Then we execute JSONTransactionSerializer.toBuffer(). We will runfinal 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
@Propertyto field X; 2. make sure field X has a getter namedgetX.To prove if I change to
I get
Suggestion
I feel this issue could be a documentation oversight as
@Propertydidn't mention getters. If maintainers like, I can add something like