jrjc JSONObject["type"] not found

Erik Macias November 13, 2017

(Posted this under discussion, but it was marked as spam, so trying here)

I am trying to set up Hygieia dashboard and while setting up the jira-collector (which has jira-rest-java-client-core v3.0.0 as a dependency) I came across the following error:

Caused by: org.codehaus.jettison.json.JSONException: JSONObject["type"] not found.
at org.codehaus.jettison.json.JSONObject.get(JSONObject.java:360) ~[jettison-1.1.jar!/:1.1]
at org.codehaus.jettison.json.JSONObject.getString(JSONObject.java:487) ~[jettison-1.1.jar!/:1.1]
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parseSchema(IssueJsonParser.java:344) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parseFields(IssueJsonParser.java:309) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:223) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:88) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.GenericJsonArrayParser.parse(GenericJsonArrayParser.java:39) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.SearchResultJsonParser.parse(SearchResultJsonParser.java:40) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.SearchResultJsonParser.parse(SearchResultJsonParser.java:27) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:145) ~[jira-rest-java-client-core-3.0.0.jar!/:na]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:186) ~[jira-rest-java-client-core-3.0.0.jar!/:na] 

The error thrown is from:

com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parseSchema(IssueJsonParser.java:344)

and that line looks like:

(line 343) JSONObject fieldDefinition = json.getJSONObject(fieldId);
(line 344) res.put(fieldId, fieldDefinition.getString("type"));  <<< res is a map returned by this method

The json object parsed by IssueJsonParser.parseSchema causing the exception looks like:

{"custom":"com.onresolve.jira.groovy.groovyrunner:scripted-field","customId":xxxxx}

which does not contain the field "type".

As IssueJsonParser.parseSchema is a private method only called by IssueJsonParser.parseFields, and that method is only concerned with values of type, "key":

res.add(new IssueField(key, namesMap.get(key), typesMap.get("key"), value != JSONObject.NULL ? value : null));

should IssueJsonParser.parseSchema check for "type" field prior to adding to the map, i.e.:

(line 344 becomes)
if (fieldDefinition.has("type")) {
res.put(fieldId, fieldDefinition.getString("type"));
}

or should com.onresolve.jira.groovy.groovyrunner:scripted-field be required to contain a "type" field?

Currently I am implementing the if-statement, but that requires me to maintain my own version of jrjc which I would rather avoid doing. I am new to Jira and jrjc so I was hoping start a discussion on whether adding the if-statement is most appropriate or if adding the "type" field is a better option. If the latter, how would one go about adding this field? Any help would be much appreciated, thanks.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 15, 2019

Please have a look at https://community.developer.atlassian.com/ for such kind of questions.