private static JsonArrayBuilder jsonArrayBuilderFromMapCounter(Map<String, List<Integer>> mapCounter) { JsonArrayBuilder arrobj = Json.createArrayBuilder(); for (Entry<String, List<Integer>> sen : mapCounter.entrySet()) { JsonObjectBuilder obj = Json.createObjectBuilder(); JsonArrayBuilder tokens = Json.createArrayBuilder(); for(Integer i : sen.getValue()){ tokens.add(i); } obj.add(sen.getKey(),tokens); arrobj.add(obj); } return arrobj; }
/** * Adds a "remove" JSON Patch operation. * @param path the "path" member of the operation * @return this JsonPatchBuilder */ @Override public JsonPatchBuilder remove(String path) { builder.add(Json.createObjectBuilder() .add("op", Operation.REMOVE.operationName()) .add("path", path) ); return this; }
@Override public void process(int id, Document document) { JsonArrayBuilder clusters = Json.createArrayBuilder(); for (CorefCluster gold : document.goldCorefClusters.values()) { JsonArrayBuilder c = Json.createArrayBuilder(); for (Mention m : gold.corefMentions) { c.add(m.mentionID); clusters.add(c.build()); JsonArrayBuilder sentences = Json.createArrayBuilder(); for (CoreMap sentence : document.annotation.get(SentencesAnnotation.class)) { sentences.add(getSentenceArray(sentence.get(CoreAnnotations.TokensAnnotation.class))); JsonArrayBuilder featureNames = Json.createArrayBuilder() .add("same-speaker") .add("antecedent-is-mention-speaker") .add("mention-is-antecedent-speaker") .add("relaxed-head-match") .add("exact-string-match") .add("relaxed-string-match"); JsonObjectBuilder features = Json.createObjectBuilder(); JsonObjectBuilder labels = Json.createObjectBuilder(); for (int val : CategoricalFeatureExtractor.pairwiseFeatures( document, m1, m2, dictionaries, conll)) { builder.add(val);
@Override public JsonArray add(JsonValue value) { //TODO should we check for arrayoutofbounds? // The spec seems to say index = array.size() is allowed. This is handled as append JsonArrayBuilder builder = Json.createArrayBuilder(this.array); if (index == -1 || index == array.size()) { builder.add(value); } else { if(index < array.size()) { builder.add(index, value); } else { throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); } } return builder.build(); }
private static String toJSON(final Map<String, Map<String, Object>[]> messages) { JsonArrayBuilder arrayReturn = JsonLoader.createArrayBuilder(); for (Map.Entry<String, Map<String, Object>[]> entry : messages.entrySet()) { JsonObjectBuilder objectItem = JsonLoader.createObjectBuilder(); objectItem.add("consumerName", entry.getKey()); objectItem.add("elements", toJSONMsgArray(entry.getValue())); arrayReturn.add(objectItem); } return arrayReturn.build().toString(); }
if (val.getClass().isArray()) { JsonArray objectArray = toJSONArray((Object[]) val); jsonObject.add(key, objectArray); } else { addToObject(key, val, jsonObject); jsonArray.add(jsonObject); } else { if (parameter != null) { for (Object data : innerArray) { String s = Base64.encodeObject((CompositeDataSupport) data); innerJsonArray.add(s); jsonObject.add(CompositeData.class.getName(), innerJsonArray); jsonArray.add(jsonObject); } else { jsonArray.add(toJSONArray(innerArray)); return jsonArray.build();
/** * "publication_statuses" : [ name 1, name 2, etc.] * * @return */ public JsonArrayBuilder getListofSelectedPublicationStatuses(){ JsonArrayBuilder jsonArray = Json.createArrayBuilder(); for (String pubStatus : this.publicationStatuses){ jsonArray.add(pubStatus); } return jsonArray; }
/** * Update an account with an ACME server using the given account information. * * @param account the ACME account information to use (must not be {@code null}) * @param staging whether or not the staging server URL should be used * @param termsOfServiceAgreed the new value for whether or not the terms of service have been agreed to * @param contactUrls the new account contact URLs * @throws AcmeException if an error occurs while attempting to update the account */ public void updateAccount(AcmeAccount account, boolean staging, boolean termsOfServiceAgreed, String[] contactUrls) throws AcmeException { Assert.checkNotNullParam("account", account); JsonObjectBuilder payloadBuilder = Json.createObjectBuilder() .add(TERMS_OF_SERVICE_AGREED, termsOfServiceAgreed); if (contactUrls != null && ! (contactUrls.length == 0)) { JsonArrayBuilder contactBuilder = Json.createArrayBuilder(); for (String contactUrl : contactUrls) { contactBuilder.add(contactUrl); } payloadBuilder.add(CONTACT, contactBuilder.build()); } sendPostRequestWithRetries(account, staging, getAccountUrl(account, staging), false, getEncodedJson(payloadBuilder.build()), HttpURLConnection.HTTP_OK); account.setTermsOfServiceAgreed(termsOfServiceAgreed); if (contactUrls != null && ! (contactUrls.length == 0)) { account.setContactUrls(contactUrls); } }
/** * Adds an "add" JSON Patch operation * @param path the "path" member of the operation * @param value the "value" member of the operation * @return this JsonPatchBuilder */ @Override public JsonPatchBuilder add(String path, boolean value) { builder.add(Json.createObjectBuilder() .add("op", Operation.ADD.operationName()) .add("path", path) .add("value", value) ); return this; }
public String getAllAnnotations(String input) { JsonObjectBuilder objsent = Json.createObjectBuilder(); int tokenid = 0; for(CoreLabel l : Data.sents.get(input).getTokens()){ boolean haslabel = false; JsonArrayBuilder labelArr = Json.createArrayBuilder(); for(Map.Entry<String, Class<? extends TypesafeMap.Key<String>>> en: this.humanLabelClasses.entrySet()){ if(!l.get(en.getValue()).equals(backgroundSymbol)){ haslabel = true; labelArr.add(en.getKey()); } } if(haslabel) objsent.add(String.valueOf(tokenid), labelArr); tokenid++; } return objsent.build().toString(); }
private boolean hasValidAudience(JsonObject claims) throws RealmUnavailableException { if (this.audiences.isEmpty()) return true; JsonValue audience = claims.get("aud"); if (audience == null) { log.debug("Token does not contain an audience claim"); return false; } JsonArray audClaimArray; if (JsonValue.ValueType.STRING.equals(audience.getValueType())) { audClaimArray = Json.createArrayBuilder().add(audience).build(); } else { audClaimArray = (JsonArray) audience; } boolean valid = audClaimArray.stream() .map(jsonValue -> (JsonString) jsonValue) .anyMatch(audience1 -> audiences.contains(audience1.getString())); if (!valid) { log.debugf("Audience check failed. Provided [%s] but was expected [%s].", audClaimArray.toArray(), this.audiences); } return valid; }
@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); } }
public static JsonArrayBuilder rolesToJson(List<DataverseRole> role) { JsonArrayBuilder bld = Json.createArrayBuilder(); for (DataverseRole r : role) { bld.add(JsonPrinter.json(r)); } return bld; }
payloadBuilder.add(ONLY_RETURN_EXISTING, true); } else { payloadBuilder.add(TERMS_OF_SERVICE_AGREED, account.isTermsOfServiceAgreed()); if (account.getContactUrls() != null && !(account.getContactUrls().length == 0)) { JsonArrayBuilder contactBuilder = Json.createArrayBuilder(); for (String contactUrl : account.getContactUrls()) { contactBuilder.add(contactUrl); payloadBuilder.add(CONTACT, contactBuilder.build());
/** * Adds a "test" JSON Patch operation. * @param path the "path" member of the operation * @param value the "value" member of the operation * @return this JsonPatchBuilder */ @Override public JsonPatchBuilder test(String path, int value) { builder.add(Json.createObjectBuilder() .add("op", Operation.TEST.operationName()) .add("path", path) .add("value", value) ); return this; }
public String getSetWordsAsJson(Map<String, Counter<CandidatePhrase>> words){ JsonObjectBuilder obj = Json.createObjectBuilder(); for(String label: getLabels()){ JsonArrayBuilder arr = Json.createArrayBuilder(); for(CandidatePhrase k: words.get(label).keySet()) arr.add(k.getPhrase()); obj.add(label, arr); } return obj.build().toString(); }
@Override public JsonArray add(JsonValue value) { //TODO should we check for arrayoutofbounds? // The spec seems to say index = array.size() is allowed. This is handled as append JsonArrayBuilder builder = Json.createArrayBuilder(this.array); if (index == -1 || index == array.size()) { builder.add(value); } else { if(index < array.size()) { builder.add(index, value); } else { throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); } } return builder.build(); }
private JsonArray getArray(JsonArrayBuilder builder) { while(hasNext()) { JsonParser.Event e = next(); if (e == JsonParser.Event.END_ARRAY) { return builder.build(); } builder.add(getValue()); } throw parsingException(JsonToken.EOF, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL, SQUARECLOSE]"); }