Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Fields missing even with @Property. Unclear documentation?

Aberta
#232 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
45/100
Tipo de issue
Documentação
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
java
Domínio
documentation

Direção de pesquisa

Comece lendo a documentação da anotação @Property juntamente com DataTypeDefinitionImpl e JSONTransactionSerializer, que o relatório identifica como os caminhos relevantes. Esclareça que um campo anotado precisa de um getter para aparecer no JSON retornado e atualize a documentação da anotação para que o comportamento esperado de serialização do exemplo Sale seja inequívoco.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.
 ...
Linguagem predominante
Java
Estrelas
322
Forks
210
Merge médio
22h 13min
PRs com merge (30d)
17

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de hyperledger/fabric-chaincode-java

Todas as issues de hyperledger/fabric-chaincode-java

Issues semelhantes

Mais issues de Java

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.