Java Code Examples for com.eclipsesource.json.JsonArray#add()
The following examples show how to use
com.eclipsesource.json.JsonArray#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoxFileUploadSession.java From box-java-sdk with Apache License 2.0 | 6 votes |
private String getCommitBody(List<BoxFileUploadSessionPart> parts, Map<String, String> attributes) { JsonObject jsonObject = new JsonObject(); JsonArray array = new JsonArray(); for (BoxFileUploadSessionPart part: parts) { JsonObject partObj = new JsonObject(); partObj.add("part_id", part.getPartId()); partObj.add("offset", part.getOffset()); partObj.add("size", part.getSize()); array.add(partObj); } jsonObject.add("parts", array); if (attributes != null) { JsonObject attrObj = new JsonObject(); for (String key: attributes.keySet()) { attrObj.add(key, attributes.get(key)); } jsonObject.add("attributes", attrObj); } return jsonObject.toString(); }
Example 2
Source File: BoxFile.java From box-java-sdk with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public BoxFile.Info setCollections(BoxCollection... collections) { JsonArray jsonArray = new JsonArray(); for (BoxCollection collection : collections) { JsonObject collectionJSON = new JsonObject(); collectionJSON.add("id", collection.getID()); jsonArray.add(collectionJSON); } JsonObject infoJSON = new JsonObject(); infoJSON.add("collections", jsonArray); String queryString = new QueryStringBuilder().appendParam("fields", ALL_FIELDS).toString(); URL url = FILE_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID()); BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT"); request.setBody(infoJSON.toString()); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); return new Info(jsonObject); }
Example 3
Source File: MetadataTemplate.java From box-java-sdk with Apache License 2.0 | 6 votes |
/** * Updates the schema of an existing metadata template. * * @param api the API connection to be used * @param scope the scope of the object * @param template Unique identifier of the template * @param fieldOperations the fields that needs to be updated / added in the template * @return the updated metadata template */ public static MetadataTemplate updateMetadataTemplate(BoxAPIConnection api, String scope, String template, List<FieldOperation> fieldOperations) { JsonArray array = new JsonArray(); for (FieldOperation fieldOperation : fieldOperations) { JsonObject jsonObject = getFieldOperationJsonObject(fieldOperation); array.add(jsonObject); } QueryStringBuilder builder = new QueryStringBuilder(); URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlpha(api.getBaseURL(), scope, template); BoxJSONRequest request = new BoxJSONRequest(api, url, "PUT"); request.setBody(array.toString()); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject responseJson = JsonObject.readFrom(response.getJSON()); return new MetadataTemplate(responseJson); }
Example 4
Source File: SyncLeads.java From REST-Sample-Code with MIT License | 6 votes |
private JsonObject buildRequest() { JsonObject requestBody = new JsonObject(); //JsonObject container for the request body //add optional params if (action != null){ requestBody.add("action", action); } if (lookupField != null){ requestBody.add("lookupField", lookupField); } //assemble the input from leads into a JsonArray JsonArray input = new JsonArray(); int i; for (i = 0; i < leads.length; i++){ input.add(leads[i]); } //add our array to the input parameter of the body requestBody.add("input", input); return requestBody; }
Example 5
Source File: MessagingStorage.java From zencash-swing-wallet-ui with MIT License | 5 votes |
/** * Adds a new ignored sender ID. This makes sense only if the * current contact is a group. The ID may be an anonymous sender UUID or a * normal from address. * * @param senderID to add */ public void addGroupIgnoredSenderID(String senderID) throws IOException { this.preloadCachedIgnoredGroupSenderIDs(); File ignoredIDsFile = new File(rootDir, IGNORED_GROUP_IDS); Util.renameFileForMultiVersionBackup(rootDir, IGNORED_GROUP_IDS); this.cachedIgnoredGroupSenderIDs.add(senderID); JsonArray ar = new JsonArray(); for (String id : this.cachedIgnoredGroupSenderIDs) { ar.add(id); } OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(ignoredIDsFile)); OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8"); ar.writeTo(osw, WriterConfig.PRETTY_PRINT); osw.flush(); } finally { if (os != null) { os.close(); } } }
Example 6
Source File: GroupJsonRuleTest.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void groupRuleShouldFailOnArraySizeRule() { JsonArray jsonArray = new JsonArray(); jsonArray.add(1); jsonArray.add(2); jsonArray.add(3); groupRule.validate(jsonArray); }
Example 7
Source File: SyncCustomObjects.java From REST-Sample-Code with MIT License | 5 votes |
private JsonObject buildRequest(){ JsonObject requestBody = new JsonObject(); //Create a new JsonObject for the Request Body JsonArray in = new JsonArray(); //Create a JsonArray for the "input" member to hold Opp records for (JsonObject jo : input) { in.add(jo); //add our Opportunity records to the input array } requestBody.add("input", in); if (this.action != null){ requestBody.add("action", action); //add the action member if available } if (this.dedupeBy != null){ requestBody.add("dedupeBy", dedupeBy); //add the dedupeBy member if available } return requestBody; }
Example 8
Source File: Metadata.java From box-java-sdk with Apache License 2.0 | 5 votes |
/** * Adds a new metadata value of array type. * @param path the path to the field. * @param values the collection of values. * @return the metadata object for chaining. */ public Metadata add(String path, List<String> values) { JsonArray arr = new JsonArray(); for (String value : values) { arr.add(value); } this.values.add(this.pathToProperty(path), arr); this.addOp("add", path, arr); return this; }
Example 9
Source File: BoxUploadSession.java From box-android-sdk with Apache License 2.0 | 5 votes |
/** * Util method for storing sha1 for parts being uploaded */ public void setPartsSha1(List<String> sha1s) { JsonArray jsonArray = new JsonArray(); for (String s : sha1s) { jsonArray.add(s); } set(FIELD_PARTS_SHA1, jsonArray); }
Example 10
Source File: VariableArrayJsonRuleTest.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void variableArrayJsonRuleShouldFailOnInvalidSecondElement() { JsonArray jsonArray = new JsonArray(); jsonArray.add(true); jsonArray.add("B"); rule.validate(jsonArray); }
Example 11
Source File: VariableArrayJsonRuleTest.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void variableArrayJsonRuleShouldFailOnInvalidElements() { JsonArray jsonArray = new JsonArray(); jsonArray.add("A"); jsonArray.add("B"); rule.validate(jsonArray); }
Example 12
Source File: R2ServerClientTest.java From r2cloud with Apache License 2.0 | 5 votes |
@Test public void testSaveMetrics() throws InterruptedException { JsonHttpResponse handler = new JsonHttpResponse("r2cloudclienttest/empty-response.json", 200); server.setMetricsMock(handler); JsonObject metric = new JsonObject(); metric.add("name", "temperature"); metric.add("value", 0.1d); JsonArray metrics = new JsonArray(); metrics.add(metric); client.saveMetrics(metrics); handler.awaitRequest(); assertEquals("application/json", handler.getRequestContentType()); assertJson("r2cloudclienttest/metrics-request.json", handler.getRequest()); }
Example 13
Source File: SSLLog.java From r2cloud with Apache License 2.0 | 5 votes |
@Override public ModelAndView doGet(IHTTPSession session) { ModelAndView result = new ModelAndView(); if (client.isRunning()) { result.setStatus(Response.Status.PARTIAL_CONTENT); } JsonArray array = new JsonArray(); int index = WebServer.getInteger(session, "index"); List<String> messages = client.getMessages(); for (int i = index; i < messages.size(); i++) { array.add(messages.get(i)); } result.setData(array.toString()); return result; }
Example 14
Source File: CaliperResultsPreprocessor.java From minimal-json with MIT License | 5 votes |
private static JsonValue extractTimes(JsonArray measurements) { JsonArray result = new JsonArray(); for (JsonValue measurement : measurements) { result.add(measurement.asObject().get("processed")); } return result; }
Example 15
Source File: BoxBrowseController.java From box-android-browse-sdk with Apache License 2.0 | 5 votes |
@Override public void saveRecentSearches(Context context, BoxUser user, ArrayList<String> searches) { JsonArray jsonArray = new JsonArray(); for(int i = 0; i < searches.size(); i++) { jsonArray.add(searches.get(i)); } context.getSharedPreferences(RECENT_SEARCHES_KEY + user.getId(), Context.MODE_PRIVATE).edit().putString(RECENT_SEARCHES_KEY, jsonArray.toString()).commit(); }
Example 16
Source File: ObservationLoad.java From r2cloud with Apache License 2.0 | 4 votes |
@Override public ModelAndView doGet(IHTTPSession session) { ValidationResult errors = new ValidationResult(); String id = WebServer.getParameter(session, "id"); if (id == null) { errors.put("id", Messages.CANNOT_BE_EMPTY); } String satelliteId = WebServer.getParameter(session, "satelliteId"); if (satelliteId == null) { errors.put("satelliteId", Messages.CANNOT_BE_EMPTY); } if (!errors.isEmpty()) { return new BadRequest(errors); } Observation entity = resultDao.find(satelliteId, id); if (entity == null) { LOG.info("not found: {} id: {}", satelliteId, id); return new NotFound(); } JsonObject json = entity.toJson(signed); if (entity.getDataPath() != null) { Decoder decoder = decoders.get(entity.getSatelliteId()); if (decoder instanceof TelemetryDecoder) { TelemetryDecoder telemetryDecoder = (TelemetryDecoder) decoder; try (BeaconInputStream<?> ais = new BeaconInputStream<>(new BufferedInputStream(new FileInputStream(entity.getDataPath())), telemetryDecoder.getBeaconClass())) { JsonArray data = new JsonArray(); while (ais.hasNext()) { data.add(convert(ais.next())); } json.add("dataEntity", data); } catch (Exception e) { LOG.error("unable to read binary data", e); } } } ModelAndView result = new ModelAndView(); result.setData(json.toString()); return result; }
Example 17
Source File: VariableArrayJsonRuleTest.java From dungeon with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void variableArrayJsonRuleShouldPassOnSingleElementArray() { JsonArray jsonArray = new JsonArray(); jsonArray.add(true); rule.validate(jsonArray); }
Example 18
Source File: BoxFileTest.java From box-java-sdk with Apache License 2.0 | 4 votes |
@Test @Category(UnitTest.class) public void getAndSetTags() { JsonObject fakeResponse = new JsonObject(); fakeResponse.add("type", "file"); fakeResponse.add("id", "1234"); JsonArray tagsJSON = new JsonArray(); tagsJSON.add("foo"); tagsJSON.add("bar"); fakeResponse.add("tags", tagsJSON); BoxAPIConnection api = new BoxAPIConnection(""); api.setRequestInterceptor(JSONRequestInterceptor.respondWith(fakeResponse)); BoxFile file = new BoxFile(api, "1234"); BoxFile.Info info = file.getInfo(); List<String> tags = info.getTags(); Assert.assertEquals("foo", tags.get(0)); Assert.assertEquals("bar", tags.get(1)); tags.add("baz"); info.setTags(tags); api.setRequestInterceptor(new JSONRequestInterceptor() { @Override protected BoxAPIResponse onJSONRequest(BoxJSONRequest request, JsonObject json) { Assert.assertEquals("foo", json.get("tags").asArray().get(0).asString()); Assert.assertEquals("bar", json.get("tags").asArray().get(1).asString()); Assert.assertEquals("baz", json.get("tags").asArray().get(2).asString()); return new BoxJSONResponse() { @Override public String getJSON() { return "{}"; } }; } }); file.updateInfo(info); }
Example 19
Source File: AndroidInjections.java From CrossMobile with GNU Lesser General Public License v3.0 | 4 votes |
private JsonArray toArray(Collection<String> data) { JsonArray array = new JsonArray(); for (String item : data) array.add(item); return array; }
Example 20
Source File: MetadataTemplateTest.java From box-java-sdk with Apache License 2.0 | 4 votes |
@Test @Category(UnitTest.class) public void testSetOptionReturnsCorrectly() throws IOException { String result = ""; final String metadataTemplateURL = "/metadata_templates/schema"; result = TestConfig.getFixture("BoxMetadataTemplate/CreateMetadataTemplate200"); JsonObject keyObject = new JsonObject(); keyObject.add("key", "FY16"); JsonObject secondKeyObject = new JsonObject(); secondKeyObject.add("key", "FY17"); JsonArray optionsArray = new JsonArray(); optionsArray.add(keyObject); optionsArray.add(secondKeyObject); JsonObject enumObject = new JsonObject(); enumObject.add("type", "enum") .add("key", "fy") .add("displayName", "FY") .add("options", optionsArray); JsonArray fieldsArray = new JsonArray(); fieldsArray.add(enumObject); JsonObject templateBody = new JsonObject(); templateBody.add("scope", "enterprise") .add("displayName", "Document Flow 03") .add("hidden", false) .add("templateKey", "documentFlow03") .add("fields", fieldsArray); WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo(metadataTemplateURL)) .withRequestBody(WireMock.equalToJson(templateBody.toString())) .willReturn(WireMock.aResponse() .withHeader("Content-Type", "application/json") .withBody(result))); MetadataTemplate.Field fyField = new MetadataTemplate.Field(); fyField.setType("enum"); fyField.setKey("fy"); fyField.setDisplayName("FY"); List<String> options = new ArrayList<String>(); options.add("FY16"); options.add("FY17"); fyField.setOptions(options); List<MetadataTemplate.Field> fields = new ArrayList<MetadataTemplate.Field>(); fields.add(fyField); MetadataTemplate template = MetadataTemplate.createMetadataTemplate(this.api, "enterprise", "documentFlow03", "Document Flow 03", false, fields); Assert.assertEquals("FY16", template.getFields().get(0).getOptions().get(0)); Assert.assertEquals("FY17", template.getFields().get(0).getOptions().get(1)); }