Dear Community,
I am using jira-rest-java-client to read an issue from JIRA Cloud
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client</artifactId>
<version>2.0.0-m2</version>
</dependency>
My code is fairly straight forward:
public static void main(String[] args) throws Exception
{
final JiraRestClientFactory
factory =
new AsynchronousJiraRestClientFactory();
final JiraRestClient
jiraRestClient =
factory
.createWithBasicHttpAuthentication(
new URI(Constants.JIRA_URL),
Constants.USERNAME,
Constants.TOKEN
);
final IssueRestClient
issueClient =
jiraRestClient.getIssueClient();
final Promise<com.atlassian.jira.rest.client.domain.Issue>
promiseIssue =
issueClient.getIssue("OTPL-5018");
final com.atlassian.jira.rest.client.domain.Issue
issue =
promiseIssue.claim();
System.out.println(issue);
}
The issue is retrieved, but during the parsing of the author, the code is trying to retrieve attribute "name" which does not appear to exist in the JSON object.
@Nullable
public static BasicUser parseBasicUser(@Nullable JSONObject json) throws JSONException {
if (json == null) {
return null;
}
final String username = json.getString("name");
if (!json.has(JsonParseUtil.SELF_ATTR) && "Anonymous".equals(username)) {
return null; // insane representation for unassigned user - JRADEV-4262
}
// deleted user? BUG in REST API: JRA-30263
final URI selfUri = optSelfUri(json, BasicUser.INCOMPLETE_URI);
return new BasicUser(selfUri, username, json.optString("displayName", null));
}
Instead, my object contains a field called "displayName".
As a result, the code in the jira-rest-java-client library fails with the following exception:
Caused by: org.codehaus.jettison.json.JSONException: JSONObject["name"] not found.
at org.codehaus.jettison.json.JSONObject.get(JSONObject.java:360)
at org.codehaus.jettison.json.JSONObject.getString(JSONObject.java:487)
at com.atlassian.jira.rest.client.internal.json.JsonParseUtil.parseBasicUser(JsonParseUtil.java:167)
Is there something that I am not doing correctly?
Why does the object returned from JIRA Cloud does not include "name", but rather has "displayName" instead?
More importantly, how do I fix this?