com.eclipsesource.json.JsonArray Java Examples

The following examples show how to use com.eclipsesource.json.JsonArray. 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: CommandFusionImporter.java    From IrScrutinizer with GNU General Public License v3.0 6 votes vote down vote up
Remote parseRemote(JsonObject jsonObject) {
    JsonObject remoteInfo = (JsonObject) jsonObject.get("RemoteInfo");
    JsonArray remoteFunctions = (JsonArray) jsonObject.get("RemoteFunctions");

    Map<String, Command> commands = new LinkedHashMap<>(8);
    for (JsonValue c : remoteFunctions) {
        Command command = parseCommand((JsonObject) c);
        if (command != null)
            commands.put(command.getName(), command);
    }
    String name = remoteInfo.getString("RemoteID", null);
    String deviceClass = remoteInfo.getString("DeviceFamily", null);
    String manufacturer = remoteInfo.getString("Manufacturer", null);
    String model = remoteInfo.getString("DeviceModel", null);
    String remoteName = remoteInfo.getString("RemoteModel", null);
    Map<String, String> notes = new HashMap<>(1);
    notes.put("Description", remoteInfo.getString("Description", null));

    Remote remote = new Remote(new Remote.MetaData(name, null, manufacturer, model, deviceClass, remoteName),
            null /* String comment */, notes, commands,
            null /* HashMap<String,HashMap<String,String>> applicationParameters*/);
    return remote;
}
 
Example #2
Source File: ForecastIO.java    From forecastio-lib-java with Eclipse Public License 1.0 6 votes vote down vote up
public ForecastIO(String LATITUDE, String LONGITUDE, String PROXYNAME, int PROXYPORT, String API_KEY){	

		if (API_KEY.length()==32) {
			this.ForecastIOApiKey = API_KEY;
			this.forecast = new JsonObject();
			this.currently = new JsonObject();
			this.minutely = new JsonObject();
			this.hourly = new JsonObject();
			this.daily = new JsonObject();
			this.flags = new JsonObject();
			this.alerts = new JsonArray();
			this.timeURL = null;
			this.excludeURL = null;
			this.extend = false;
			this.unitsURL = UNITS_AUTO;
			this.langURL = LANG_ENGLISH;
			this.proxy_to_use = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXYNAME, PROXYPORT));

			getForecast(LATITUDE, LONGITUDE);
		}
		else {
			System.err.println("The API Key doesn't seam to be valid.");
		}

	}
 
Example #3
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
public synchronized boolean isSendingOperationComplete(String opID)
    throws WalletCallException, IOException, InterruptedException
{
	JsonArray response = this.executeCommandAndGetJsonArray(
		"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
	JsonObject jsonStatus = response.get(0).asObject();

	String status = jsonStatus.getString("status", "ERROR");

	Log.info("Operation " + opID + " status is " + response + ".");

	if (status.equalsIgnoreCase("success") ||
		status.equalsIgnoreCase("error") ||
		status.equalsIgnoreCase("failed"))
	{
		return true;
	} else if (status.equalsIgnoreCase("executing") || status.equalsIgnoreCase("queued"))
	{
		return false;
	} else
	{
		throw new WalletCallException("Unexpected status response from wallet: " + response.toString());
	}
}
 
Example #4
Source File: MetersResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of a rest api GET for a device with meter id.
 */
@Test
public void testMeterSingleDeviceWithId() {
    setupMockMeters();

    expect(mockMeterService.getMeter(anyObject(), anyObject()))
            .andReturn(meter5).anyTimes();
    replay(mockMeterService);
    replay(mockDeviceService);

    final WebTarget wt = target();
    final String response = wt.path("meters/" + deviceId3.toString()
            + "/" + meter5.id().id()).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter5));
}
 
Example #5
Source File: BoxWebHook.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Setter for {@link #getTriggers()}.
 *
 * @param triggers
 *            {@link #getTriggers()}
 * @return itself
 */
public Info setTriggers(Set<BoxWebHook.Trigger> triggers) {
    validateTriggers(this.target.getType(), triggers);

    JsonArray oldValue;
    if (this.triggers != null) {
        oldValue = toJsonArray(CollectionUtils.map(this.triggers, TRIGGER_TO_VALUE));
    } else {
        oldValue = null;
    }
    JsonArray newValue = toJsonArray(CollectionUtils.map(triggers, TRIGGER_TO_VALUE));

    if (!newValue.equals(oldValue)) {
        this.triggers = Collections.unmodifiableSet(triggers);
        this.addPendingChange(JSON_KEY_TRIGGERS, newValue);
    }

    return this;
}
 
Example #6
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
public synchronized String getSuccessfulOperationTXID(String opID)
       throws WalletCallException, IOException, InterruptedException
{
	String TXID = null;
	JsonArray response = this.executeCommandAndGetJsonArray(
		"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
	JsonObject jsonStatus = response.get(0).asObject();
	JsonValue  opResultValue = jsonStatus.get("result"); 
	
	if (opResultValue != null)
	{
		JsonObject opResult = opResultValue.asObject();
		if (opResult.get("txid") != null)
		{
			TXID = opResult.get("txid").asString();
		}
	}
	
	return TXID;
}
 
Example #7
Source File: ForecastIO.java    From forecastio-lib-java with Eclipse Public License 1.0 6 votes vote down vote up
public ForecastIO(String LATITUDE, String LONGITUDE, String API_KEY){	

		if (API_KEY.length()==32) {
			this.ForecastIOApiKey = API_KEY;
			this.forecast = new JsonObject();
			this.currently = new JsonObject();
			this.minutely = new JsonObject();
			this.hourly = new JsonObject();
			this.daily = new JsonObject();
			this.flags = new JsonObject();
			this.alerts = new JsonArray();
			this.timeURL = null;
			this.excludeURL = null;
			this.extend = false;
			this.unitsURL = UNITS_AUTO;
			this.langURL = LANG_ENGLISH;
			this.proxy_to_use = null;

			getForecast(LATITUDE, LONGITUDE);
		}
		else {
			System.err.println("The API Key doesn't seam to be valid.");
		}

	}
 
Example #8
Source File: FlowsResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matchesSafely(JsonArray json) {
    boolean flowFound = false;

    for (int jsonFlowIndex = 0; jsonFlowIndex < json.size();
         jsonFlowIndex++) {

        final JsonObject jsonFlow = json.get(jsonFlowIndex).asObject();

        final String flowId = Long.toString(flow.id().value());
        final String jsonFlowId = jsonFlow.get("id").asString();
        if (jsonFlowId.equals(flowId)) {
            flowFound = true;

            //  We found the correct flow, check attribute values
            assertThat(jsonFlow, matchesFlow(flow, APP_ID.name()));
        }
    }
    if (!flowFound) {
        reason = "Flow with id " + flow.id().toString() + " not found";
        return false;
    } else {
        return true;
    }
}
 
Example #9
Source File: BoxFolder.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Gets information about all of the collaborations for this folder.
 *
 * @return a collection of information about the collaborations for this folder.
 */
public Collection<BoxCollaboration.Info> getCollaborations() {
    BoxAPIConnection api = this.getAPI();
    URL url = GET_COLLABORATIONS_URL.build(api.getBaseURL(), this.getID());

    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int entriesCount = responseJSON.get("total_count").asInt();
    Collection<BoxCollaboration.Info> collaborations = new ArrayList<BoxCollaboration.Info>(entriesCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        JsonObject entryObject = entry.asObject();
        BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString());
        BoxCollaboration.Info info = collaboration.new Info(entryObject);
        collaborations.add(info);
    }

    return collaborations;
}
 
Example #10
Source File: MetricsController.java    From r2cloud with Apache License 2.0 6 votes vote down vote up
@Override
public ModelAndView doGet(IHTTPSession session) {
	ModelAndView result = new ModelAndView();
	JsonArray array = new JsonArray();
	for (Entry<String, Metric> cur : metrics.getRegistry().getMetrics().entrySet()) {
		JsonObject curObject = new JsonObject();
		curObject.add("id", cur.getKey());
		curObject.add("url", signed.sign("/api/v1/admin/static/rrd/" + cur.getKey() + ".rrd"));
		if (cur.getValue() instanceof FormattedGauge<?>) {
			curObject.add("format", ((FormattedGauge<?>) cur.getValue()).getFormat().toString());
		}
		array.add(curObject);
	}
	result.setData(array.toString());
	return result;
}
 
Example #11
Source File: BoxUser.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Gets information about all of the group memberships for this user.
 * Does not support paging.
 *
 * <p>Note: This method is only available to enterprise admins.</p>
 *
 * @return a collection of information about the group memberships for this user.
 */
public Collection<BoxGroupMembership.Info> getMemberships() {
    BoxAPIConnection api = this.getAPI();
    URL url = USER_MEMBERSHIPS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());

    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int entriesCount = responseJSON.get("total_count").asInt();
    Collection<BoxGroupMembership.Info> memberships = new ArrayList<BoxGroupMembership.Info>(entriesCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        JsonObject entryObject = entry.asObject();
        BoxGroupMembership membership = new BoxGroupMembership(api, entryObject.get("id").asString());
        BoxGroupMembership.Info info = membership.new Info(entryObject);
        memberships.add(info);
    }

    return memberships;
}
 
Example #12
Source File: BoxRequest.java    From box-android-sdk with Apache License 2.0 6 votes vote down vote up
protected void parseHashMapEntry(JsonObject jsonBody, Map.Entry<String, Object> entry) {
    Object obj = entry.getValue();
    if (obj instanceof BoxJsonObject) {
        jsonBody.add(entry.getKey(), parseJsonObject(obj));
    } else if (obj instanceof Double) {
        jsonBody.add(entry.getKey(), Double.toString((Double) obj));
    } else if (obj instanceof Enum || obj instanceof Boolean) {
        jsonBody.add(entry.getKey(), obj.toString());
    } else if (obj instanceof JsonArray) {
        jsonBody.add(entry.getKey(), (JsonArray) obj);
    } else if (obj instanceof Long) {
        jsonBody.add(entry.getKey(), JsonValue.valueOf((Long)obj));
    } else if (obj instanceof Integer) {
        jsonBody.add(entry.getKey(), JsonValue.valueOf((Integer)obj));
    } else if (obj instanceof Float) {
        jsonBody.add(entry.getKey(), JsonValue.valueOf((Float)obj));
    } else if (obj instanceof String) {
        jsonBody.add(entry.getKey(), (String) obj);
    } else {
        BoxLogUtils.e("Unable to parse value " + obj, new RuntimeException("Invalid value"));
    }

}
 
Example #13
Source File: IrdbImporter.java    From IrScrutinizer with GNU General Public License v3.0 6 votes vote down vote up
private static void setupManufacturers(boolean verbose) throws IOException {
    ArrayList<String> newManufacturers = new ArrayList<>(1024);
    String path = String.format(urlFormatBrands, 1);
    for (int index = 1; index <= 100 && !path.isEmpty(); index++) {
        JsonObject o = getJsonObject(path, verbose);
        JsonValue meta = o.get("meta");
        JsonObject metaObject = meta.asObject();
        path = metaObject.get("next").asString();
        if (verbose)
            System.err.println("Read page " + metaObject.get("page").asInt());
        JsonArray objects = o.get("objects").asArray();
        for (JsonValue val : objects) {
            JsonObject obj = val.asObject();
            String brand = obj.get("brand").asString();
            if (!newManufacturers.contains(brand))
                newManufacturers.add(brand);
        }
    }
    manufacturers = newManufacturers;
}
 
Example #14
Source File: RequestCampaign.java    From REST-Sample-Code with MIT License 6 votes vote down vote up
private JsonObject buildRequest(){
JsonObject jo = new JsonObject();//parent object
JsonObject input = new JsonObject();//inut object to hold arrays of tokens and leads
JsonArray leads = new JsonArray();
int i;
for (i = 0; i < leadIds.length; i++) {
	leads.add(leadIds[i]);
}
input.add("leads", leads);
//assemble array of tokens and add to input if present
if (tokens != null){
	JsonArray tokensArray = new JsonArray();
	for (JsonObject jsonObject : tokens) {
		tokensArray.add(jsonObject);
		}
	input.add("tokens", tokensArray);
	}
//add input as a member of the parent
jo.add("input", input);
return jo;
}
 
Example #15
Source File: BoxFile.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of any comments on this file.
 *
 * @return a list of comments on this file.
 */
public List<BoxComment.Info> getComments() {
    URL url = GET_COMMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int totalCount = responseJSON.get("total_count").asInt();
    List<BoxComment.Info> comments = new ArrayList<BoxComment.Info>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject commentJSON = value.asObject();
        BoxComment comment = new BoxComment(this.getAPI(), commentJSON.get("id").asString());
        BoxComment.Info info = comment.new Info(commentJSON);
        comments.add(info);
    }

    return comments;
}
 
Example #16
Source File: GroupsResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of a rest api GET for a device.
 */
@Test
public void testGroupsSingleDevice() {
    setupMockGroups();
    final Set<Group> groups = new HashSet<>();
    groups.add(group5);
    groups.add(group6);
    expect(mockGroupService.getGroups(anyObject()))
            .andReturn(groups).anyTimes();
    replay(mockGroupService);
    replay(mockDeviceService);
    final WebTarget wt = target();
    final String response = wt.path("groups/" + deviceId3).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("groups"));
    final JsonArray jsonGroups = result.get("groups").asArray();
    assertThat(jsonGroups, notNullValue());
    assertThat(jsonGroups, hasGroup(group5));
    assertThat(jsonGroups, hasGroup(group6));
}
 
Example #17
Source File: Config.java    From JWT4B with GNU General Public License v3.0 6 votes vote down vote up
private static String generateDefaultConfigFile() {
	JsonObject configJO = new JsonObject();
	
	JsonArray jwtKeywordsJA = new JsonArray();
	for (String jwtKeyword : jwtKeywords) {
		jwtKeywordsJA.add(jwtKeyword);
	}
	
	JsonArray tokenKeywordsJA = new JsonArray();
	for (String tokenKeyword : tokenKeywords) {
		tokenKeywordsJA.add(tokenKeyword);
	}
	
	configJO.add("resetEditor", true);
	configJO.add("highlightColor", highlightColor);
	configJO.add("interceptComment", interceptComment);
	configJO.add("jwtKeywords",jwtKeywordsJA);
	configJO.add("tokenKeywords",tokenKeywordsJA);
	
	configJO.add("cveAttackModePublicKey", cveAttackModePublicKey);
	configJO.add("cveAttackModePrivateKey", cveAttackModePrivateKey);
	
	return configJO.toString(WriterConfig.PRETTY_PRINT);
}
 
Example #18
Source File: SyncLeads.java    From REST-Sample-Code with MIT License 6 votes vote down vote up
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 #19
Source File: BoxTask.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Gets any assignments for this task.
 * @return a list of assignments for this task.
 */
public List<BoxTaskAssignment.Info> getAssignments() {
    URL url = GET_ASSIGNMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int totalCount = responseJSON.get("total_count").asInt();
    List<BoxTaskAssignment.Info> assignments = new ArrayList<BoxTaskAssignment.Info>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject assignmentJSON = value.asObject();
        BoxTaskAssignment assignment = new BoxTaskAssignment(this.getAPI(), assignmentJSON.get("id").asString());
        BoxTaskAssignment.Info info = assignment.new Info(assignmentJSON);
        assignments.add(info);
    }

    return assignments;
}
 
Example #20
Source File: MappingsWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET when there are active mappings.
 */
@Test
public void testMappingsPopulateArray() {
    setupMockMappings();
    expect(mockMappingService.getAllMappingEntries(anyObject()))
            .andReturn(mappingEntries).once();
    replay(mockMappingService);
    final WebTarget wt = target();
    final String response = wt.path(PREFIX + "/" + DATABASE).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("mappings"));
    final JsonArray jsonMappings = result.get("mappings").asArray();
    assertThat(jsonMappings, notNullValue());
    assertThat(jsonMappings, hasMapping(mapping1));
    assertThat(jsonMappings, hasMapping(mapping2));
    assertThat(jsonMappings, hasMapping(mapping3));
    assertThat(jsonMappings, hasMapping(mapping4));
}
 
Example #21
Source File: MulticastRouteResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the results of the REST API GET when there are active mcastroutes.
 */
@Test
public void testMcastRoutePopulatedArray() {
    initMcastRouteMocks();
    final Set<McastRoute> mcastRoutes = ImmutableSet.of(route1, route2, route3);
    expect(mockMulticastRouteService.getRoutes()).andReturn(mcastRoutes).anyTimes();
    replay(mockMulticastRouteService);

    final WebTarget wt = target();
    final String response = wt.path("mcast").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("routes"));
    final JsonArray jsonMcastRoutes = result.get("routes").asArray();
    assertThat(jsonMcastRoutes, notNullValue());
    assertThat(jsonMcastRoutes, hasMcastRoute(route1));
    assertThat(jsonMcastRoutes, hasMcastRoute(route2));
    assertThat(jsonMcastRoutes, hasMcastRoute(route3));
}
 
Example #22
Source File: GroupsResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET when there are active groups.
 */
@Test
public void testGroupsPopulatedArray() {
    setupMockGroups();
    replay(mockGroupService);
    replay(mockDeviceService);
    final WebTarget wt = target();
    final String response = wt.path("groups").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("groups"));
    final JsonArray jsonGroups = result.get("groups").asArray();
    assertThat(jsonGroups, notNullValue());
    assertThat(jsonGroups, hasGroup(group1));
    assertThat(jsonGroups, hasGroup(group2));
    assertThat(jsonGroups, hasGroup(group3));
    assertThat(jsonGroups, hasGroup(group4));
}
 
Example #23
Source File: ContactImpl.java    From Skype4J with Apache License 2.0 5 votes vote down vote up
private static JsonObject getObject(SkypeImpl skype, String username) throws ConnectionException {
    JsonArray array = Endpoints.PROFILE_INFO
            .open(skype)
            .expect(200, "While getting contact info")
            .as(JsonArray.class)
            .post(new JsonObject()
                    .add("usernames", new JsonArray()
                            .add(username)
                    )
            );
    return array.get(0).asObject();
}
 
Example #24
Source File: FixedArrayJsonRuleTest.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void fixedStringIntegerArrayRuleShouldFailOnInvalidArray() {
  JsonArray jsonArray = new JsonArray();
  jsonArray.add(0);
  jsonArray.add("A");
  stringIntegerArrayRule.validate(jsonArray);
}
 
Example #25
Source File: StatisticsResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests GET of all Load statistics objects.
 */
@Test
public void testLoadsGet() throws UnsupportedEncodingException {
    final WebTarget wt = target();
    final String response = wt.path("statistics/flows/link/").request().get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("loads"));

    final JsonArray jsonLoads = result.get("loads").asArray();
    assertThat(jsonLoads, notNullValue());
    assertThat(jsonLoads.size(), is(3));

    // Hash the loads by the current field to allow easy lookup if the
    // order changes.
    HashMap<Integer, JsonObject> currentMap = new HashMap<>();
    IntStream.range(0, jsonLoads.size())
            .forEach(index -> currentMap.put(
                    jsonLoads.get(index).asObject().get("latest").asInt(),
                    jsonLoads.get(index).asObject()));

    JsonObject load1 = currentMap.get(2);
    checkValues(load1, 1, 2, true, "src1");

    JsonObject load2 = currentMap.get(22);
    checkValues(load2, 11, 22, true, "src2");

    JsonObject load3 = currentMap.get(222);
    checkValues(load3, 111, 222, true, "src3");

}
 
Example #26
Source File: CaliperResultsPreprocessor.java    From minimal-json with MIT License 5 votes vote down vote up
private static JsonValue extractTimes(JsonArray measurements) {
  JsonArray result = new JsonArray();
  for (JsonValue measurement : measurements) {
    result.add(measurement.asObject().get("processed"));
  }
  return result;
}
 
Example #27
Source File: Metadata.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a patch operation.
 * @param op the operation type. Must be add, replace, remove, or test.
 * @param path the path that designates the key. Must be prefixed with a "/".
 * @param value the value to be set.
 */
private void addOp(String op, String path, String value) {
    if (this.operations == null) {
        this.operations = new JsonArray();
    }

    this.operations.add(new JsonObject()
            .add("op", op)
            .add("path", path)
            .add("value", value));
}
 
Example #28
Source File: VariableArrayJsonRuleTest.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void variableArrayJsonRuleShouldPassOnMultipleElementArray() {
  JsonArray jsonArray = new JsonArray();
  jsonArray.add(true);
  jsonArray.add(false);
  rule.validate(jsonArray);
}
 
Example #29
Source File: CaliperResultsPreprocessor.java    From minimal-json with MIT License 5 votes vote down vote up
private static JsonArray extractMeasurements(JsonObject caliperResults) {
  JsonArray result = new JsonArray();
  JsonArray measurements = caliperResults.get("run").asObject().get("measurements").asArray();
  for (JsonValue measurement : measurements) {
    result.add(extractMeasurement(measurement.asObject()));
  }
  return result;
}
 
Example #30
Source File: DescribeSalesPersons.java    From REST-Sample-Code with MIT License 5 votes vote down vote up
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;
}