Search in sources :

Example 61 with JSONArray

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;
}
Also used : JSONObject(net.minidev.json.JSONObject) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) JSONArray(net.minidev.json.JSONArray)

Example 62 with JSONArray

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);
}
Also used : Hook(org.btrplace.plan.event.Action.Hook) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Event(org.btrplace.plan.event.Event) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 63 with JSONArray

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;
}
Also used : Action(org.btrplace.plan.event.Action) JSONObject(net.minidev.json.JSONObject) Model(org.btrplace.model.Model) JSONArray(net.minidev.json.JSONArray) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 64 with JSONArray

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");
}
Also used : JSONArray(net.minidev.json.JSONArray) Test(org.junit.Test)

Example 65 with JSONArray

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);
}
Also used : JSONArray(net.minidev.json.JSONArray) Test(org.junit.Test)

Aggregations

JSONArray (net.minidev.json.JSONArray)71 JSONObject (net.minidev.json.JSONObject)52 Test (org.junit.Test)13 HashMap (java.util.HashMap)10 JSONParser (net.minidev.json.parser.JSONParser)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 HashSet (java.util.HashSet)6 List (java.util.List)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 JSONConverterException (org.btrplace.json.JSONConverterException)5 Test (org.testng.annotations.Test)5 DocumentContext (com.jayway.jsonpath.DocumentContext)3 JsonPath (com.jayway.jsonpath.JsonPath)3 Option (com.jayway.jsonpath.Option)3 ContentType (ddf.catalog.data.ContentType)3 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)3 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)3 SourceDescriptor (ddf.catalog.source.SourceDescriptor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3