问题描述
我尝试在用户故事中添加讨论.部分代码
I try to add Discussion to User Story. Part of code
QueryResponse storyQueryResponse = restApi.query(storyRequest);
JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject();
String storyRef = storyJsonObject.get("_ref").toString();
System.out.println("Ref: " + storyRef);
Ref ref = new Ref();
System.out.println(ref.getOidFromRef(storyRef));
System.out.println(ref.isRef(storyRef));
createDis.addProperty("Artifact", ref.getOidFromRef(storyRef));
createDis.addProperty("Text", "Java-Java-Java-Java-Java-Java-Java-Java-Java-Java-Java-Java");
CreateRequest createRequest = new CreateRequest("ConversationPost", createDis);
CreateResponse createResponse = restApi.create(createRequest);
System.out.println("Ref: " + storyRef) return参考:"https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/13097497257"
System.out.println("Ref: " + storyRef) returnRef: "https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/13097497257"
ref.getOidFromRef(storyRef) 返回 NULLref.isRef(storyRef) 返回 FALSE
ref.getOidFromRef(storyRef) return NULLref.isRef(storyRef) return FALSE
为什么???
推荐答案
此行无效,导致您的 ref 周围有一组额外的引号:
This line is invalid and is causing your ref to have an extra set of quotes around it:
String storyRef = storyJsonObject.get("_ref").toString();
将其更改为此应该可以使其正常工作:
Changing it to this should get it to work correctly:
String storyRef = storyJsonObject.get("_ref").getAsString();
始终使用 getAs 方法而不是 toString.
Always use the getAs methods rather than toString.
这篇关于通过 REST API Java 从 URL 获取 ObjectID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!