我创建了 Java Chaincode 并将其部署在 Fabric 2.2 网络上。一切似乎都正常,但是当我从分类帐中进行任何查询时,我得到空白的 JSON 响应。我在日志中没有看到任何问题,所以似乎一切正常,但不知何故响应是空白的。
@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;}}