use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class SplitAmongConverter method toJSON.
@Override
public JSONObject toJSON(SplitAmong o) {
JSONObject c = new JSONObject();
c.put("id", getJSONId());
JSONArray vGroups = new JSONArray();
for (Collection<VM> grp : o.getGroupsOfVMs()) {
vGroups.add(vmsToJSON(grp));
}
JSONArray pGroups = new JSONArray();
for (Collection<Node> grp : o.getGroupsOfNodes()) {
pGroups.add(nodesToJSON(grp));
}
c.put("vParts", vGroups);
c.put("pParts", pGroups);
c.put("continuous", o.isContinuous());
return c;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class ReconfigurationPlanConverter method eventsToJSON.
private void eventsToJSON(final Action action, final JSONObject json) throws JSONConverterException {
final JSONObject hooks = new JSONObject();
for (final Hook k : Hook.values()) {
final JSONArray arr = new JSONArray();
for (final Event ev : action.getEvents(k)) {
final EventConverter c = java2json.get(ev.getClass());
if (c == null) {
throw new JSONConverterException("No converter " + "registered for '" + ev + "'");
}
arr.add(c.toJSON(ev));
}
hooks.put(k.toString(), arr);
}
json.put(HOOK_LABEL, hooks);
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class ReconfigurationPlanConverter method toJSON.
@Override
public JSONObject toJSON(ReconfigurationPlan plan) throws JSONConverterException {
final JSONObject ob = new JSONObject();
final Model src = plan.getOrigin();
ob.put(ORIGIN_LABEL, mc.toJSON(src));
final JSONArray actions = new JSONArray();
for (final Action a : plan.getActions()) {
final ActionConverter ac = java3json.get(a.getClass());
if (ac == null) {
throw new JSONConverterException("No converter registered for '" + a.getClass() + "'");
}
final JSONObject json = ac.toJSON(a);
eventsToJSON(a, json);
actions.add(json);
}
ob.put(ACTIONS_LABEL, actions);
return ob;
}
use of net.minidev.json.JSONArray in project JsonPath by jayway.
the class Issue273 method testGetPropertyFromArray.
@Test
public void testGetPropertyFromArray() {
String json = "[\n" + " [\n" + " {\n" + " \"category\" : \"reference\",\n" + " \"author\" : \"Nigel Rees\",\n" + " \"title\" : \"Sayings of the Century\",\n" + " \"price\" : 8.95\n" + " },\n" + " {\n" + " \"category\" : \"fiction\",\n" + " \"author\" : \"Evelyn Waugh\",\n" + " \"title\" : \"Sword of Honour\",\n" + " \"price\" : 12.99\n" + " },\n" + " {\n" + " \"category\" : \"fiction\",\n" + " \"author\" : \"Herman Melville\",\n" + " \"title\" : \"Moby Dick\",\n" + " \"isbn\" : \"0-553-21311-3\",\n" + " \"price\" : 8.99\n" + " },\n" + " {\n" + " \"category\" : \"fiction\",\n" + " \"author\" : \"J. R. R. Tolkien\",\n" + " \"title\" : \"The Lord of the Rings\",\n" + " \"isbn\" : \"0-395-19395-8\",\n" + " \"price\" : 22.99\n" + " }\n" + " ],\n" + " {\n" + " \"color\" : \"red\",\n" + " \"price\" : 19.95\n" + " }\n" + "]\n";
JSONArray arr = JsonPath.read(json, "$..[2].author");
assertEquals(arr.get(0), "Herman Melville");
}
use of net.minidev.json.JSONArray in project JsonPath by jayway.
the class JSONEntityPathFunctionTest method testPredicateWithFunctionCallTwoMatches.
@Test
public void testPredicateWithFunctionCallTwoMatches() {
String path = "$.batches.results[?(@.values.length() >= 3)].values.avg()";
// Its an array because in some use-cases the min size might match more than one batch and thus we'll get
// the average out for each collection
JSONArray values = new JSONArray();
values.add(12.2d);
values.add(17d);
verifyFunction(conf, path, BATCH_JSON, values);
}
Aggregations