/** * Processes a part of package.json (as defined by JsonArray) and update the * specified dependency with relevant info. * * @param engine the dependency-check engine * @param dependency the Dependency to update * @param jsonArray the jsonArray to parse * @param depType the dependency type */ protected void processPackage(Engine engine, Dependency dependency, JsonArray jsonArray, String depType) { final JsonObjectBuilder builder = Json.createObjectBuilder(); for (JsonString str : jsonArray.getValuesAs(JsonString.class)) { builder.add(str.toString(), ""); } final JsonObject jsonObject = builder.build(); processPackage(engine, dependency, jsonObject, depType); }
private static String getProblemMessages(JsonObject errorResponse) { StringBuilder problemMessages = new StringBuilder(); String mainProblem = getProblemMessage(errorResponse); if (mainProblem != null) { problemMessages.append(getProblemMessage(errorResponse)); } JsonArray subproblems = errorResponse.getJsonArray(SUBPROBLEMS); if (subproblems != null && subproblems.size() > 0) { problemMessages.append(":"); for (JsonObject subproblem : subproblems.getValuesAs(JsonObject.class)) { problemMessages.append("\n").append(getProblemMessage(subproblem)); } } return problemMessages.toString(); }
String[] queryAccountContactUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostAsGetRequest(account, staging, getAccountUrl(account, staging), null, HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); JsonArray contactsArray = jsonResponse.getJsonArray(CONTACT); if (contactsArray != null && contactsArray.size() > 0) { List<String> contacts = new ArrayList<>(contactsArray.size()); for (JsonString contact : contactsArray.getValuesAs(JsonString.class)) { contacts.add(contact.getString()); } return contacts.toArray(new String[contacts.size()]); } return null; }
LOGGER.debug("Found packages"); final JsonArray packages = composer.getJsonArray("packages"); for (JsonObject pkg : packages.getValuesAs(JsonObject.class)) { if (pkg.containsKey("name")) { final String groupName = pkg.getString("name");
private AcmeChallenge respondToChallenges(AcmeAccount account, boolean staging, JsonObject authorization) throws AcmeException { List<AcmeChallenge> challenges = null; if (authorization.getString(STATUS).equals(PENDING)) { JsonObject identifier = authorization.getJsonObject(IDENTIFIER); JsonArray challengeArray = authorization.getJsonArray(CHALLENGES); challenges = new ArrayList<>(challengeArray.size()); for (JsonObject challenge : challengeArray.getValuesAs(JsonObject.class)) { challenges.add(new AcmeChallenge(AcmeChallenge.Type.forName(challenge.getString(TYPE)), challenge.getString(URL), challenge.getString(TOKEN), identifier.getString(TYPE), identifier.getString(VALUE))); } } if (challenges != null && ! challenges.isEmpty()) { AcmeChallenge selectedChallenge = proveIdentifierControl(account, challenges); try { sendPostRequestWithRetries(account, staging, selectedChallenge.getUrl(), false, getEncodedJson(EMPTY_PAYLOAD), HttpURLConnection.HTTP_OK); return selectedChallenge; } catch (AcmeException e) { cleanupAfterChallenge(account, selectedChallenge); throw e; } } return null; }
if (caaIdentitiesArray != null) { final List<String> caaIdentities = new ArrayList<>(caaIdentitiesArray.size()); for (JsonString caaIdentity : caaIdentitiesArray.getValuesAs(JsonString.class)) { caaIdentities.add(caaIdentity.getString());
final JsonArray authorizationsArray = jsonResponse.getJsonArray(AUTHORIZATIONS); final List<String> authorizationUrls = new ArrayList<>(authorizationsArray.size()); for (JsonString authorization : authorizationsArray.getValuesAs(JsonString.class)) { authorizationUrls.add(authorization.getString());
for (JsonObject component : components.getValuesAs(JsonObject.class)) { typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) {
private static List<JsonObject> getJsonValueAsList(JsonValue value) { if (value != null) { if (value.getValueType() == ValueType.ARRAY) { return value.asJsonArray().getValuesAs(JsonObject.class); } else if (value.getValueType() == ValueType.OBJECT) { List<JsonObject> ret = new ArrayList<>(); ret.add(value.asJsonObject()); return ret; } } return null; }
/** * List of plugin options. * @return List of Privilege's values. */ public Collection<String> value() { return this.getJsonArray("Value") .getValuesAs(JsonString.class) .stream() .map(JsonString::getString) .collect(Collectors.toList()); } }
@SuppressWarnings("unchecked") @Override public Set<String> getGroups() { JsonArray groupList = (JsonArray) jsonClaims.get(Claims.groups.name()); if (groupList == null) { return null; } return groupList.getValuesAs(JsonString.class).stream().map(JsonString::getString).collect(Collectors.toSet()); }
public List<DatasetField> parseMultipleFieldsForDelete(JsonObject json) throws JsonParseException { List<DatasetField> fields = new LinkedList<>(); for (JsonObject fieldJson : json.getJsonArray("fields").getValuesAs(JsonObject.class)) { fields.add(parseFieldForDelete(fieldJson)); } return fields; }
URL url = new URL("https://graph.facebook.com/search?q=java&type=post"); try (InputStream is = url.openStream(); JsonReader rdr = Json.createReader(is)) { JsonObject obj = rdr.readObject(); JsonArray results = obj.getJsonArray("data"); for (JsonObject result : results.getValuesAs(JsonObject.class)){ System.out.print(result.getJsonObject("from").getString("name")); System.out.print(": "); System.out.println(result.getString("message", "")); System.out.println("-----------"); } }
public List<TopLevelDocument<String>> readTLDs(JsonArray jsonArray) { List<TopLevelDocument<String>> docs = new ArrayList<>(jsonArray.size()); for(JsonObject object : jsonArray.getValuesAs(JsonObject.class)) { docs.add(readTLD(object)); } return docs; }
String url = "http://api.goeuro.com/api/v2/position/suggest/en/"; String city = "New York"; Client client = ClientBuilder.newClient(); WebTarget webTarget = client.register(JsonProcessingFeature.class).target(url); JsonArray jsonArray = webTarget.path(city) .request(MediaType.APPLICATION_JSON_TYPE).get(JsonArray.class); for (JsonObject jsonObject : jsonArray.getValuesAs(JsonObject.class)) { JsonObject geoPosition = jsonObject.getJsonObject("geo_position"); System.out.println(Arrays.asList( jsonObject.getString("name"), jsonObject.getString("type"), geoPosition.get("latitude"), geoPosition.get("longitude"))); }
public static List<RsyncSite> getRsyncSites(Dataset dataset, JsonArray rsalSitesAsJson) { List<RsyncSite> rsalSites = new ArrayList<>(); boolean leafDirectoryOnly = false; String fullRemotePathToDirectory = getDirectoryContainingTheData(dataset, leafDirectoryOnly); for (JsonObject site : rsalSitesAsJson.getValuesAs(JsonObject.class)) { String name = site.getString("name"); String fqdn = site.getString("fqdn"); RsyncSite rsyncSite = new RsyncSite(name, fqdn, fullRemotePathToDirectory); rsalSites.add(rsyncSite); } return rsalSites; }
@Override public void endCompoundValue(DatasetFieldCompoundValue dsfcv) { JsonArray jsonValues = valueArrStack.pop().build(); if (!jsonValues.isEmpty()) { JsonObjectBuilder jsonField = jsonObjectBuilder(); for (JsonObject jobj : jsonValues.getValuesAs(JsonObject.class)) { jsonField.add(jobj.getString("typeName"), jobj); } valueArrStack.peek().add(jsonField); } } }
JsonReader rdr = Json.createReader(is)) { JsonObject obj = rdr.readObject(); JsonArray results = obj.getJsonArray("licenceDetail"); for (JsonObject result : results.getValuesAs(JsonObject.class)) { String Landing result.getJsonObject("Default Value").getString("Landing port"); }
@Then("^the json response \"([^\"]*)\" attribute \"([^\"]*)\" should each contain \"([^\"]*)\"$") public void checkJsonArrayContains(final String jsonArray, final String attribute, final String expected) { JsonArray array = getArrayFromJSONResponse(jsonArray); for (JsonObject obj : array.getValuesAs(JsonObject.class)) { String actual = obj.getString(attribute); assertTrue("JSON response doesn't contain expected value, has: " + actual, actual.contains(expected)); } }
private Book bookFromJson(JsonObject obj) { final Book book = new Book(obj.getString("name"), obj.getInt("id")); final JsonArray chapters = (JsonArray)obj.get("chapters"); if (chapters != null && !chapters.isEmpty()) { for (final JsonObject chapter: chapters.getValuesAs(JsonObject.class)) { book.addChapter(chapter.getInt("id"), chapter.getString("title")); } } return book; }