JsonArray array = json.readArray(); if (array == null || array.isEmpty()) { return tree;
JsonArray results = json.getJsonArray("results"); if (!results.isEmpty()) { Address address = new Address();
@Override public Address parseAddress(JsonObject json) { JsonArray result = json.getJsonArray("features"); if (result != null && !result.isEmpty()) { JsonObject location = result.getJsonObject(0).getJsonObject("properties"); Address address = new Address(); address.setCountry("FR"); if (location.containsKey("postcode")) { address.setPostcode(location.getString("postcode")); } if (location.containsKey("context")) { address.setDistrict(location.getString("context")); } if (location.containsKey("name")) { address.setStreet(location.getString("name")); } if (location.containsKey("city")) { address.setSettlement(location.getString("city")); } if (location.containsKey("housenumber")) { address.setHouse(location.getString("housenumber")); } if (location.containsKey("label")) { address.setFormattedAddress(location.getString("label")); } return address; } return null; }
if (identities != null && !identities.isEmpty()) { for (int i = 0; i < identities.size(); i++) { JsonObject identity = identities.getJsonObject(i);
if (errors != null && !errors.isEmpty()) { JsonObject jo = errors.getJsonObject(0); String errorMsg = format("[HTTP Status Code: %d] - %s request to %s failed request body %s error message: [Error Code %d] - %s", if (errors != null && !errors.isEmpty()) { JsonObject jo = errors.getJsonObject(0); HTTPException e = new HTTPException(format("%s request to %s failed request body %s error message: [Error Code %d] - %s", if (messages != null && !messages.isEmpty()) { JsonObject jo = messages.getJsonObject(0); String message = format("%s request to %s failed request body %s response message: [Error Code %d] - %s",
if (statusCode < 400) { JsonArray certificates = result.getJsonArray("certs"); if (certificates != null && !certificates.isEmpty()) { for (int i = 0; i < certificates.size(); i++) { String certPEM = certificates.getJsonObject(i).getString("PEM");
HFCAAffiliationResp(JsonObject result) { if (result.containsKey("affiliations")) { JsonArray affiliations = result.getJsonArray("affiliations"); if (affiliations != null && !affiliations.isEmpty()) { for (int i = 0; i < affiliations.size(); i++) { JsonObject aff = affiliations.getJsonObject(i); this.childHFCAAffiliations.add(new HFCAAffiliation(aff)); } } } if (result.containsKey("identities")) { JsonArray ids = result.getJsonArray("identities"); if (ids != null && !ids.isEmpty()) { for (int i = 0; i < ids.size(); i++) { JsonObject id = ids.getJsonObject(i); HFCAIdentity hfcaID = new HFCAIdentity(id); this.identities.add(hfcaID); } } } if (result.containsKey("statusCode")) { this.statusCode = result.getInt("statusCode"); } } }
private void generateResponse(JsonObject result) { if (result.containsKey("name")) { this.name = result.getString("name"); } if (result.containsKey("affiliations")) { JsonArray affiliations = result.getJsonArray("affiliations"); if (affiliations != null && !affiliations.isEmpty()) { for (int i = 0; i < affiliations.size(); i++) { JsonObject aff = affiliations.getJsonObject(i); this.childHFCAAffiliations.add(new HFCAAffiliation(aff)); } } } if (result.containsKey("identities")) { JsonArray ids = result.getJsonArray("identities"); if (ids != null && !ids.isEmpty()) { for (int i = 0; i < ids.size(); i++) { JsonObject id = ids.getJsonObject(i); HFCAIdentity hfcaID = new HFCAIdentity(id); this.identities.add(hfcaID); } } } }
JsonArray results = json.getJsonArray("results"); if (!results.isEmpty()) { Address address = new Address();
if (messages != null && !messages.isEmpty()) { JsonObject jo = messages.getJsonObject(0); String message = format("Enroll request response message [code %d]: %s", jo.getInt("code"), jo.getString("message"));
if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i);
private void getHFCAIdentity(JsonObject result) { type = result.getString("type"); if (result.containsKey("secret")) { this.secret = result.getString("secret"); } maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; }
@Override public void endField(DatasetField f) { JsonObjectBuilder jsonField = objectStack.pop(); JsonArray jsonValues = valueArrStack.pop().build(); if (!jsonValues.isEmpty()) { jsonField.add("value", f.getDatasetFieldType().isAllowMultiples() ? jsonValues : jsonValues.get(0)); valueArrStack.peek().add(jsonField); } }
@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); } } }
private static String getProperty(String property, Response response) { if (isStatusOk(response)) { String json = response.readEntity(String.class); JsonReader reader = Json.createReader(new StringReader(json)); JsonArray jsonArray = reader.readArray(); if (!jsonArray.isEmpty()) { return jsonArray.getJsonObject(0).getString(property); } } return null; } }
private TypeIdentifier analyzeInternal(final JsonArray jsonArray) { final TypeIdentifier containedIdentifier = jsonArray.isEmpty() ? TypeIdentifier.ofType(Types.OBJECT) : analyzeInternal(jsonArray.get(0)); final TypeRepresentation containedRepresentation = typeRepresentations.getOrDefault(containedIdentifier, TypeRepresentation.ofConcrete(containedIdentifier)); final TypeIdentifier existingCollection = findExistingCollection(containedRepresentation); if (existingCollection != null) { return existingCollection; } final TypeIdentifier identifier = TypeIdentifier.ofDynamic(); typeRepresentations.put(identifier, TypeRepresentation.ofCollection(identifier, containedRepresentation)); return identifier; }
private TypeIdentifier analyzeInternal(final JsonArray jsonArray) { final TypeIdentifier containedIdentifier = jsonArray.isEmpty() ? TypeIdentifier.ofType(Types.OBJECT) : analyzeInternal(jsonArray.get(0)); final TypeRepresentation containedRepresentation = typeRepresentations.getOrDefault(containedIdentifier, TypeRepresentation.ofConcrete(containedIdentifier)); final TypeIdentifier existingCollection = findExistingCollection(containedRepresentation); if (existingCollection != null) { return existingCollection; } final TypeIdentifier identifier = TypeIdentifier.ofDynamic(); typeRepresentations.put(identifier, TypeRepresentation.ofCollection(identifier, containedRepresentation)); return identifier; }
/** * Read the addresses present in the JSON object into the given person object. * * @param src The source JSON containing the address(es). * @param person The destination {@link Person} to update. */ private void readAddresses(@Nonnull JsonObject src, @Nonnull Person person) { final JsonArray addressesJson = src.getJsonArray(ADDRESSES_PROP); if (addressesJson == null || addressesJson.isEmpty()) { return; } readAddress(person, addressesJson.getJsonObject(0)); }
@Then("^the json response \"([^\"]*)\" contains an empty \"([^\"]*)\" array$") public void checkJSONResponseContainsEmptyArray(final String jsonPath, final String attribute) { JsonObject response = getObjectFromJSONResponse(jsonPath); JsonArray array = response.getJsonArray(attribute); assertTrue("JSON Response contains non-empty array \"" + attribute + "\"", array.isEmpty()); }
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; }