List of usage examples for javax.json JsonObject containsKey
boolean containsKey(Object key);
From source file:org.kuali.rice.krad.web.controller.helper.DataTablesPagingHelper.java
/** * Get the sort type string from the parsed column definitions object. * * @param jsonColumnDefs the JsonArray representation of the aoColumnDefs property from the RichTable template * options// w ww . ja v a2 s.c o m * @param sortCol the index of the column to get the sort type for * @return the name of the sort type specified in the template options, or the default of "string" if none is * found. */ private String getSortType(JsonArray jsonColumnDefs, int sortCol) { String sortType = "string"; // default to string if nothing is spec'd if (jsonColumnDefs != null) { JsonObject column = jsonColumnDefs.getJsonObject(sortCol); if (column.containsKey("sType")) { sortType = column.getString("sType"); } } return sortType; }
From source file:nl.nn.adapterframework.align.Json2Xml.java
@Override public Iterable<JsonValue> getNodeChildrenByName(JsonValue node, XSElementDeclaration childElementDeclaration) throws SAXException { String name = childElementDeclaration.getName(); if (DEBUG)//from w ww . j a va 2s .c om log.debug("getChildrenByName() childname [" + name + "] isParentOfSingleMultipleOccurringChildElement [" + isParentOfSingleMultipleOccurringChildElement() + "] isMultipleOccuringChildElement [" + isMultipleOccurringChildElement(name) + "] node [" + node + "]"); try { if (!(node instanceof JsonObject)) { if (DEBUG) log.debug("getChildrenByName() parent node is not a JsonObject, but a [" + node.getClass().getName() + "]"); return null; } JsonObject o = (JsonObject) node; if (!o.containsKey(name)) { if (DEBUG) log.debug("getChildrenByName() no children named [" + name + "] node [" + node + "]"); return null; } JsonValue child = o.get(name); List<JsonValue> result = new LinkedList<JsonValue>(); if (child instanceof JsonArray) { if (DEBUG) log.debug("getChildrenByName() child named [" + name + "] is a JsonArray, current node insertElementContainerElements [" + insertElementContainerElements + "]"); // if it could be necessary to insert elementContainers, we cannot return them as a list of individual elements now, because then the containing element would be duplicated // we also cannot use the isSingleMultipleOccurringChildElement, because it is not valid yet if (!isMultipleOccurringChildElement(name)) { if (insertElementContainerElements || !strictSyntax) { result.add(child); if (DEBUG) log.debug("getChildrenByName() singleMultipleOccurringChildElement [" + name + "] returning array node (insertElementContainerElements=true)"); } else { throw new SAXException(MSG_EXPECTED_SINGLE_ELEMENT + " [" + name + "]"); } } else { if (DEBUG) log.debug("getChildrenByName() childname [" + name + "] returning elements of array node (insertElementContainerElements=false or not singleMultipleOccurringChildElement)"); result.addAll((JsonArray) child); } return result; } result.add(child); if (DEBUG) log.debug("getChildrenByName() name [" + name + "] returning [" + child + "]"); return result; } catch (JsonException e) { throw new SAXException(e); } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
private void getHFCAIdentity(JsonObject result) { type = result.getString("type"); if (result.containsKey("secret")) { this.secret = result.getString("secret"); }/* ww w. j a v a 2 s . c o m*/ 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; }
From source file:org.bsc.confluence.rest.AbstractRESTConfluenceService.java
protected Stream<JsonObject> mapToStream(Response res) { final ResponseBody body = res.body(); try (Reader r = body.charStream()) { final JsonReader rdr = Json.createReader(r); final JsonObject root = rdr.readObject(); final Stream.Builder<JsonObject> stream = Stream.builder(); // Check for Array if (root.containsKey("results")) { final JsonArray results = root.getJsonArray("results"); if (results != null) { for (int ii = 0; ii < results.size(); ++ii) stream.add(results.getJsonObject(ii)); }/*from w w w. j a va2 s .c om*/ } else { stream.add(root); } return stream.build(); } catch (IOException | JsonParsingException e) { throw new Error(e); } }
From source file:tools.xor.logic.DefaultJson.java
protected void checkEmptyLongField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getSalary() == null); assert (!employee.getIsCriticalSystemObject()); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (!json.containsKey("salary")); }
From source file:org.apache.tamaya.etcd.EtcdAccessor.java
/** * Recursively read out all key/values from this etcd JSON array. * * @param result map with key, values and metadata. * @param node the node to parse.//www .j a va2s . c om */ private void addNodes(Map<String, String> result, JsonObject node) { if (!node.containsKey("dir") || "false".equals(node.get("dir").toString())) { final String key = node.getString("key").substring(1); result.put(key, node.getString("value")); if (node.containsKey("createdIndex")) { result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex"))); } if (node.containsKey("modifiedIndex")) { result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex"))); } if (node.containsKey("expiration")) { result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration"))); } if (node.containsKey("ttl")) { result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl"))); } result.put("_" + key + ".source", "[etcd]" + serverURL); } else { final JsonArray nodes = node.getJsonArray("nodes"); if (nodes != null) { for (int i = 0; i < nodes.size(); i++) { addNodes(result, nodes.getJsonObject(i)); } } } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAAffiliation.java
HFCAAffiliationResp getResponse(JsonObject result) { if (result.containsKey("name")) { this.name = result.getString("name"); }// w w w. j a va 2 s. c o m return new HFCAAffiliationResp(result); }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private Set<String> extractContentTagSet(JsonObject talkObject) { if (talkObject.containsKey("tags")) { return talkObject.getJsonArray("tags").stream().map(JsonObject.class::cast) .filter(tagObject -> !tagObject.getString("value").isEmpty()) .map(tagObject -> tagObject.getString("value")).collect(Collectors.toSet()); }// w ww. j a va 2s .c om return new HashSet<>(); }
From source file:org.hyperledger.fabric_ca.sdk.HFCAAffiliation.java
private void generateResponse(JsonObject result) { if (result.containsKey("name")) { this.name = result.getString("name"); }/* w w w. j a va 2 s .c o m*/ 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); } } } }
From source file:org.apache.tamaya.etcd.EtcdAccessor.java
/** * Deletes a given key. The response is as follows: * /*ww w . j a va 2 s .co m*/ * <pre> * _key.source=[etcd]http://127.0.0.1:4001 * _key.createdIndex=12 * _key.modifiedIndex=34 * _key.ttl=300 * _key.expiry=... * // optional * _key.prevNode.createdIndex=12 * _key.prevNode.modifiedIndex=34 * _key.prevNode.ttl=300 * _key.prevNode.expiration=... * _key.prevNode.value=... * </pre> * * @param key the key to be deleted. * @return the response mpas as described above. */ public Map<String, String> delete(String key) { final Map<String, String> result = new HashMap<>(); try { final HttpDelete delete = new HttpDelete(serverURL + "/v2/keys/" + key); delete.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout) .setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build()); try (CloseableHttpResponse response = httpclient.execute(delete)) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final HttpEntity entity = response.getEntity(); final JsonReader reader = readerFactory .createReader(new StringReader(EntityUtils.toString(entity))); final JsonObject o = reader.readObject(); final JsonObject node = o.getJsonObject("node"); if (node.containsKey("createdIndex")) { result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex"))); } if (node.containsKey("modifiedIndex")) { result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex"))); } if (node.containsKey("expiration")) { result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration"))); } if (node.containsKey("ttl")) { result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl"))); } parsePrevNode(key, result, o); EntityUtils.consume(entity); } } } catch (final Exception e) { LOG.log(Level.INFO, "Error deleting key '" + key + "' from etcd: " + serverURL, e); result.put("_ERROR", "Error deleting '" + key + "' from etcd: " + serverURL + ": " + e.toString()); } return result; }