/** * * @param o the {@link JSONObject} representing the warning * @throws JSONException if the argument does not match the expected format */ @Restricted(NoExternalUse.class) public Warning(JSONObject o) { try { this.type = Type.valueOf(o.getString("type").toUpperCase(Locale.US)); } catch (IllegalArgumentException ex) { this.type = Type.UNKNOWN; } this.id = o.getString("id"); this.component = Util.intern(o.getString("name")); this.message = o.getString("message"); this.url = o.getString("url"); if (o.has("versions")) { JSONArray versions = o.getJSONArray("versions"); List<WarningVersionRange> ranges = new ArrayList<>(versions.size()); for (int i = 0; i < versions.size(); i++) { WarningVersionRange range = new WarningVersionRange(versions.getJSONObject(i)); ranges.add(range); } this.versionRanges = Collections.unmodifiableList(ranges); } else { this.versionRanges = Collections.emptyList(); } }
private Map<String, JSONObject> convertToTokenMap(Object tokenStoreData) { if (tokenStoreData == null) { // in case there are no token return Collections.emptyMap(); } else if (tokenStoreData instanceof JSONObject) { // in case there is only one token JSONObject singleTokenData = (JSONObject) tokenStoreData; Map<String, JSONObject> result = new HashMap<>(); addJSONTokenIntoMap(result, singleTokenData); return result; } else if (tokenStoreData instanceof JSONArray) { // in case there are multiple tokens JSONArray tokenArray = ((JSONArray) tokenStoreData); Map<String, JSONObject> result = new HashMap<>(); for (int i = 0; i < tokenArray.size(); i++) { JSONObject tokenData = tokenArray.getJSONObject(i); addJSONTokenIntoMap(result, tokenData); } return result; } throw HttpResponses.error(400, "Unexpected class received for the token store information"); }
for (int i = 0; i < w.size(); i++) { try { warnings.add(new Warning(w.getJSONObject(i)));
/** * @param str a JSON array representation of a list of {@link AuthorityURLInfo} objects * @return the list of parsed authrority URL from the argument JSON array * @throws IllegalArgumentException if {@code str} can't be parsed to a JSONArray */ public static List<AuthorityURLInfo> fromString(String str) throws IllegalArgumentException { try { final JSONArray array; array = JSONArray.fromObject(str); final int size = array.size(); List<AuthorityURLInfo> list = new ArrayList<AuthorityURLInfo>(size); JSONObject jsonAuth; for (int i = 0; i < size; i++) { jsonAuth = array.getJSONObject(i); AuthorityURL auth = new AuthorityURL(); auth.setName(jsonAuth.getString(NAME)); auth.setHref(jsonAuth.getString(HREF)); list.add(auth); } return list; } catch (JSONException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
/** * @param str a JSON array representation of a list of {@link LayerIdentifierInfo} objects * @return the list of parsed layer identifiers from the argument JSON array * @throws IllegalArgumentException if {@code str} can't be parsed to a JSONArray */ public static List<LayerIdentifierInfo> fromString(String str) throws IllegalArgumentException { try { final JSONArray array; array = JSONArray.fromObject(str); final int size = array.size(); List<LayerIdentifierInfo> list = new ArrayList<LayerIdentifierInfo>(size); JSONObject jsonAuth; for (int i = 0; i < size; i++) { jsonAuth = array.getJSONObject(i); LayerIdentifier id = new LayerIdentifier(); id.setAuthority(jsonAuth.getString(AUTHORITY)); id.setIdentifier(jsonAuth.getString(IDENTIFIER)); list.add(id); } return list; } catch (JSONException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
/** * Installs a list of plugins from a JSON POST. * @param req The request object. * @return A JSON response that includes a "correlationId" in the "data" element. * That "correlationId" can then be used in calls to * {@link UpdateCenter#doInstallStatus(org.kohsuke.stapler.StaplerRequest)}. * @throws IOException Error reading JSON payload fro request. */ @RequirePOST @Restricted(DoNotUse.class) // WebOnly public HttpResponse doInstallPlugins(StaplerRequest req) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String payload = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding()); JSONObject request = JSONObject.fromObject(payload); JSONArray pluginListJSON = request.getJSONArray("plugins"); List<String> plugins = new ArrayList<>(); for (int i = 0; i < pluginListJSON.size(); i++) { plugins.add(pluginListJSON.getString(i)); } UUID correlationId = UUID.randomUUID(); try { boolean dynamicLoad = request.getBoolean("dynamicLoad"); install(plugins, dynamicLoad, correlationId); JSONObject responseData = new JSONObject(); responseData.put("correlationId", correlationId.toString()); return hudson.util.HttpResponses.okJSON(responseData); } catch (Exception e) { return hudson.util.HttpResponses.errorJSON(e.getMessage()); } }
/** * @param list the list of auth urls to serialize * @return {@code null} if {@code list} is null, empty, or contains only null objects; the JSON * array representation of {@code list} otherwise, with any null element stripped off. */ public static String toString(List<LayerIdentifierInfo> list) { if (list == null || list.isEmpty()) { return null; } JSONArray array = new JSONArray(); for (LayerIdentifierInfo id : list) { if (id == null) { continue; } JSONObject jsonId = new JSONObject(); jsonId.put(AUTHORITY, id.getAuthority()); jsonId.put(IDENTIFIER, id.getIdentifier()); array.add(jsonId); } if (array.size() == 0) { // list was made of only null objects? return null; } String serialized = array.toString(); return serialized; } }
/** * @param list the list of layer identifiers to serialize * @return {@code null} if {@code list} is null, empty or contains only null objects; the JSON * array representation of {@code list} otherwise, with any null element stripped off. */ public static String toString(List<AuthorityURLInfo> obj) { if (obj == null || obj.isEmpty()) { return null; } JSONArray array = new JSONArray(); for (AuthorityURLInfo auth : obj) { if (auth == null) { continue; } JSONObject jsonAuth = new JSONObject(); jsonAuth.put(NAME, auth.getName()); jsonAuth.put(HREF, auth.getHref()); array.add(jsonAuth); } if (array.size() == 0) { // list was made of only null objects? return null; } String serialized = array.toString(); return serialized; } }
Object protocols = json.get("agentProtocol"); if (protocols instanceof JSONArray) { for (int i = 0; i < ((JSONArray) protocols).size(); i++) { agentProtocols.add(((JSONArray) protocols).getString(i));
public static <T> List<T> readList(JSONArray list, Unmarshaller<T> unmarshaller) { if (list == null || list.isEmpty()) { return Collections.emptyList(); } List<T> values = new ArrayList<T>(list.size()); for (int i = 0; i < list.size(); i++) { values.add(unmarshaller.unmarshal(list, i)); } return values; }
private List<String> FromJsonArray(JSONArray jsonArray) { List<String> list = new ArrayList<String>(); for (int i = 0; i < jsonArray.size(); i++) { list.add(jsonArray.getString(i)); } return list; }
public void SetMachineList(JSONArray machineListJSONArray) { machineList = new ArrayList<String>(); for(int i = 0;i < machineListJSONArray.size();i++) { String machine = machineListJSONArray.getString(i); machineList.add(machine); } }
private static List<String> formatList(JSONArray array, String key) { List<String> result = new ArrayList<String>(); if (array != null) { for (int i = 0; i < array.size(); i++) { result.add(array.getJSONObject(i).getString(key)); } } return result; }
protected ArrayList<String> ExtractConfigsFromResponse(JSONObject object) { ArrayList<String> configs = new ArrayList<String>(); JSONArray configobj = object.getJSONArray("configs"); for (int i = 0; i < configobj.size(); ++i) { configs.add(configobj.getString(i)); } return configs; }
public void SetKey(JSONArray key) throws LogException { try { this.key = new ArrayList<String>(); for (int i = 0; i < key.size(); i++) { this.key.add(key.getString(i)); } } catch (JSONException e) { throw new LogException("FailToSetKey", e.getMessage(), e, ""); } }
public void SetFilterRegex(JSONArray filterRegex) throws LogException { try { this.filterRegex = new ArrayList<String>(); for (int i = 0; i < filterRegex.size(); i++) { this.filterRegex.add(filterRegex.getString(i)); } } catch (JSONException e) { throw new LogException("FailToSetFilterRegex", e.getMessage(), e, ""); } }
private List<ShipperTask> ExtractShipperTask(JSONObject object) { List<ShipperTask> res = new ArrayList<ShipperTask>(); JSONArray array = object.getJSONArray("tasks"); for (int i = 0; i < array.size(); i++) { JSONObject item = array.getJSONObject(i); ShipperTask task = new ShipperTask(); task.FromJsonObject(item); res.add(task); } return res; }
@Test public void testGetAllByWorkspaceJSON() throws Exception { JSONObject json = (JSONObject) getAsJSON(RestBaseController.ROOT_PATH + "/workspaces/wcs/coverages.json"); JSONArray coverages = json.getJSONObject("coverages").getJSONArray("coverage"); assertEquals( catalog.getCoveragesByNamespace(catalog.getNamespaceByPrefix("wcs")).size(), coverages.size()); }
@Test public void testGetWithCountAndStartIndex0() throws Exception { JSONObject json = (JSONObject) getAsJSON( "wfs?request=GetFeature&typenames=cdf:Fifteen&version=1.1.0&service=wfs&maxFeatures=5&startIndex=0&outputFormat=JSON"); assertEquals(5, json.getJSONArray("features").size()); assertEquals(15, json.getInt("totalFeatures")); }
@Test public void testGetWithCountAndStartIndexMiddle() throws Exception { JSONObject json = (JSONObject) getAsJSON( "wfs?request=GetFeature&typenames=cdf:Fifteen&version=1.1.0&service=wfs&maxFeatures=5&startIndex=7&outputFormat=JSON"); assertEquals(5, json.getJSONArray("features").size()); assertEquals(15, json.getInt("totalFeatures")); }