Exception while trying to read project role using jira-rest-java-client-core SDK

Nimisha Menon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 11, 2021

I need to get project and its members from JIRA

I have added following dependencies -

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.2.2</version>
</dependency>

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-app</artifactId>
<version>5.2.1</version>
</dependency>

This is my code for fetching the actors details from project role1   

1  JiraRestClient jiraRestClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(URI.create(url),username,password);
2 ProjectRestClient prjClient = jiraRestClient.getProjectClient();
3 Promise<Iterable<BasicProject>> jiraProjects = prjClient.getAllProjects();
4 Iterable<BasicProject> basicProjects = Optional.ofNullable((Iterable<BasicProject>) jiraProjects.claim()).orElseThrow(() -> new Exception("No projects"));
5 for (BasicProject project : basicProjects)
6 {
7 Promise<Project> prj = prjClient.getProject(project.getKey());
8 Project p = Optional.ofNullable((Project) prj.claim()).orElseThrow(() -> new Exception("No such project"));
9 Iterable<BasicProjectRole> roles = p.getProjectRoles();
10 for (BasicProjectRole basicProjectRole : roles)
11 {
12 Promise<ProjectRole> role = jiraRestClient.getProjectRolesRestClient().getRole(basicProjectRole.getSelf());
13 ProjectRole r = Optional.ofNullable((ProjectRole) role.claim()).orElseThrow(() -> new Exception("No such role"));
14 Iterable<RoleActor> a = r.getActors();
15 }
16 }
17 jiraRestClient.close();

But I am getting below exception on line 13 in above code.

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.RoleActorJsonParser.parse(RoleActorJsonParser.java:40)
at com.atlassian.jira.rest.client.internal.json.RoleActorJsonParser.parse(RoleActorJsonParser.java:26)
at com.atlassian.jira.rest.client.internal.json.JsonParseUtil.parseJsonArray(JsonParseUtil.java:51)
at com.atlassian.jira.rest.client.internal.json.ProjectRoleJsonParser.parse(ProjectRoleJsonParser.java:45)
at com.atlassian.jira.rest.client.internal.json.ProjectRoleJsonParser.parse(ProjectRoleJsonParser.java:29)
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:148)
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:189)
... 15 more

The projects are retrived. But while fetching the project role, during the parsing of the RoleActor, the code is trying to retrieve attribute "name" which does not appear to exist in the JSON object.  

 @Override
public RoleActor parse(final JSONObject json) throws JSONException {
// Workaround for a bug in API. Id field should not be optional, unfortunately it is not returned for an admin role actor.
final Long id = JsonParseUtil.getOptionalLong(json, "id");
final String displayName = json.getString("displayName");
final String type = json.getString("type");
final String name = json.getString("name");
return new RoleActor(id, displayName, type, name, parseAvatarUrl(json));
}

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?

I need following details about all the projects in JIRA
name
despription
start date
end date
status
all the members added to this project

Is there any other API that I can use to get these values ?

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events