@SuppressWarnings("unchecked") public IssueField parse(JSONObject jsonObject, String id) throws JSONException { String type = jsonObject.getString("type"); final String name = jsonObject.getString("name"); final Object valueObject = jsonObject.opt(VALUE_ATTRIBUTE); final Object value; // @todo ugly hack until https://jdog.atlassian.com/browse/JRADEV-3220 is fixed if ("comment".equals(name)) { type = "com.atlassian.jira.Comment"; } if (valueObject == null) { value = null; } else { final JsonObjectParser valueParser = registeredValueParsers.get(type); if (valueParser != null) { value = valueParser.parse(jsonObject); } else { value = valueObject.toString(); } } return new IssueField(id, name, type, value); }
@SuppressWarnings("unchecked") public IssueField parse(JSONObject jsonObject, String id) throws JSONException { String type = jsonObject.getString("type"); final String name = jsonObject.getString("name"); final Object valueObject = jsonObject.opt(VALUE_ATTRIBUTE); final Object value; // @todo ugly hack until https://jdog.atlassian.com/browse/JRADEV-3220 is fixed if ("comment".equals(name)) { type = "com.atlassian.jira.Comment"; } if (valueObject == null) { value = null; } else { final JsonObjectParser valueParser = registeredValueParsers.get(type); if (valueParser != null) { value = valueParser.parse(jsonObject); } else { value = valueObject.toString(); } } return new IssueField(id, name, type, value); }
res.add(new IssueField(key, namesMap.get(key), typesMap.get("key"), value != JSONObject.NULL ? value : null)); } catch (final Exception e) { throw new JSONException("Error while parsing [" + key + "] field: " + e.getMessage()) {
private Collection<IssueField> parseFields(final JSONObject issueJson) throws JSONException { final JSONObject names = (providedNames != null) ? providedNames : issueJson.optJSONObject(NAMES_SECTION); final Map<String, String> namesMap = parseNames(names); final JSONObject schema = (providedSchema != null) ? providedSchema : issueJson.optJSONObject(SCHEMA_SECTION); final Map<String, String> typesMap = parseSchema(schema); final JSONObject json = issueJson.getJSONObject(FIELDS); final ArrayList<IssueField> res = new ArrayList<IssueField>(json.length()); @SuppressWarnings("unchecked") final Iterator<String> iterator = json.keys(); while (iterator.hasNext()) { final String key = iterator.next(); try { if (SPECIAL_FIELDS.contains(key)) { continue; } // TODO: JRJC-122 // we should use fieldParser here (some new version as the old one probably won't work) // enable IssueJsonParserTest#testParseIssueWithUserPickerCustomFieldFilledOut after fixing this final Object value = json.opt(key); res.add(new IssueField(key, namesMap.get(key), typesMap.get("key"), value != JSONObject.NULL ? value : null)); } catch (final Exception e) { throw new JSONException("Error while parsing [" + key + "] field: " + e.getMessage()) { @Override public Throwable getCause() { return e; } }; } } return res; }