Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Fields missing even with @Property. Unclear documentation?

Offen
#232 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
45/100
Issue-Typ
Dokumentation
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
java
Bereich
documentation

Rechercherichtung

Beginne damit, die Dokumentation der Annotation @Property zusammen mit DataTypeDefinitionImpl und JSONTransactionSerializer zu lesen, die im Bericht als relevante Pfade identifiziert werden. Stelle klar, dass ein annotiertes Feld einen Getter benötigt, um im zurückgegebenen JSON zu erscheinen, und aktualisiere die Dokumentation der Annotation, damit das erwartete Serialisierungsverhalten des Sale-Beispiels eindeutig ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.
 ...
Vorherrschende Sprache
Java
Sterne
322
Forks
210
Ø Merge
15 Std. 16 Min.
Gemergte PRs (30 T.)
29

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus hyperledger/fabric-chaincode-java

Alle Issues in hyperledger/fabric-chaincode-java

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.