Java Chaincode Query function provide blank JSON response in Fabric 2.2

191 views Asked by At

I have created Java Chaincode and deployed it on Fabric 2.2 network. Everything seems to be working but when I do any query from the ledger, I am getting blank JSON Response. I don't see any issue in logs so seems like everything is working but somehow response is blank.

@Transaction()
        public Car queryCarById(final Context ctx, final String id) {
            ChaincodeStub stub = ctx.getStub();
            String CarState = stub.getStringState(id);
            if (CarState.isEmpty()) {
                String errorMessage = String.format("Car %s does not exist", id);
                System.out.println(errorMessage);
                throw new ChaincodeException(errorMessage, CarTransferErrors.Car_NOT_FOUND.toString());
            }
            Car Car = genson.deserialize(CarState, Car.class);
            System.out.println(Car);
            return Car;
        }



package Cartransfer;

import com.owlike.genson.annotation.JsonProperty;
import org.hyperledger.fabric.contract.annotation.DataType;
import org.hyperledger.fabric.contract.annotation.Property;

    @DataType()
    public final class Car {
    @Property()
    private final String id;

    @Property()
    private final String name;

    @Property()
    private final String area;

    @Property()
    private final String ownerName;
    
    @Property()
    private final String value;
    
    public String getid() {
        return id;
    }

    public String getname() {
        return name;
    }

    public String getarea() {
        return area;
    }

    public String getownerName() {
        return ownerName;
    }
    public String getvalue() {
        return value;
    }
    
    public Car(@JsonProperty("id") final String id, @JsonProperty("name") final String name,
            @JsonProperty("area") final String area, @JsonProperty("ownerName") final String ownerName,
            @JsonProperty("value") final String value) {
        this.id = id;
        this.name = name;
        this.area = area;
        this.ownerName = ownerName;this.value= value;}}
1

There are 1 answers

0
RaspiRepo On

May be you make a test transactions to network (after deploy your chain code success) ? Following script might helpful to verify seperatly

https://github.com/hyperledger/fabric-samples/blob/75e3be113726d83a2de6d427608a0fec8e9b9711/test-network/scripts/deployCC.sh#L274

and use this method to query chain code (to verify txn's on the ledger

https://github.com/hyperledger/fabric-samples/blob/75e3be113726d83a2de6d427608a0fec8e9b9711/test-network/scripts/deployCC.sh#L293