我正在尝试使用Java中的Rally REST API创建缺陷。
我插入缺陷的代码如下所示:
JsonObject newDefect = new JsonObject();
newDefect.addProperty("Workspace", workspaceRef);
newDefect.addProperty("Project", projectRef);
newDefect.addProperty("Name", d.name);
newDefect.addProperty("Description", d.description);
newDefect.addProperty("Notes", d.notes);
newDefect.addProperty("Owner", getUserReference(restApi, d.owner));
System.out.println("Creating defect: " + d.qcid + " - " + d.name);
CreateRequest createRequest = new CreateRequest("defect", newDefect);
CreateResponse createResponse = restApi.create(createRequest);
getUserReference的实现如下:
private String getUserReference(RallyRestApi restApi, String name) throws Exception
{
// Read User
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", name));
QueryResponse userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonElement userQueryElement = userQueryResults.get(0);
JsonObject userQueryObject = userQueryElement.getAsJsonObject();
String userRef = userQueryObject.get("_ref").toString();
return userRef;
}
问题:用户收到错误“无法解析对象引用”。当我使用实际名称([email protected])或如上所述的用户参考时,就会得到它。
我得到的当前错误是:无法从““ https://rally1.rallydev.com/slm/webservice/v2.0/user/14659049875”“解析对象引用
我究竟做错了什么?
谢谢
阿萨夫
最佳答案
请使用getAsString方法而不是toString。
尝试:
String userRef = userQueryObject.get("_ref").getAsString();
代替
String userRef = userQueryObject.get("_ref").toString();