Fields missing even with @Property. Unclear documentation?
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 45/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- java
- Ambito
- documentation
Direzione di ricerca
Inizia leggendo la documentazione dell’annotazione @Property insieme a DataTypeDefinitionImpl e JSONTransactionSerializer, che il report identifica come i percorsi rilevanti. Chiarisci che un campo annotato ha bisogno di un getter per apparire nel JSON restituito e aggiorna la documentazione dell’annotazione in modo che il comportamento di serializzazione previsto dell’esempio Sale sia inequivocabile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
...
- Lingua principale
- Java
- Stelle
- 322
- Fork
- 210
- Merge medio
- 15h 16m
- PR unite (30g)
- 29
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di hyperledger/fabric-chaincode-java
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
hyperledger/fabric-chaincode-java#628 ·
I maintainer di solito rispondono entro 1 giorno
-
Optimize ClassGraph ScanningApertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
hyperledger/fabric-chaincode-java#627 ·
I maintainer di solito rispondono entro 1 giorno
-
DataType nested classApertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 75/100
hyperledger/fabric-chaincode-java#626 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
hyperledger/fabric-chaincode-java#625 ·
I maintainer di solito rispondono entro 1 giorno
-
Read/write batchingForse di nuovo libera @jadebluestar l’ha presa 119 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement help wanted
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
hyperledger/fabric-chaincode-java#378 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di hyperledger/fabric-chaincode-java
Issue simili
-
[GLOBAL] Advancement resetAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
Vakore/ZappierGames#184 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
lugassawan/swe-workbench#823 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cassiancc/Raspberry-Core#69 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
IronCoreLabs/ironcore-alloy#351 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
checkstyle/checkstyle#22145 ·
I maintainer di solito rispondono entro 1 giorno