Example usage for org.json.simple JSONObject toJSONString

List of usage examples for org.json.simple JSONObject toJSONString

Introduction

In this page you can find the example usage for org.json.simple JSONObject toJSONString.

Prototype

public String toJSONString() 

Source Link

Usage

From source file:functionaltests.RestSchedulerTagTest.java

@Test
public void testTaskResultValueByTag() throws Exception {
    HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tag/LOOP-T2-1/result/value");
    JSONObject jsonObject = toJsonObject(response);

    System.out.println(jsonObject.toJSONString());

    assertTrue(jsonObject.containsKey("T1#1"));
    assertTrue(jsonObject.containsKey("Print1#1"));
    assertTrue(jsonObject.containsKey("Print2#1"));
    assertTrue(jsonObject.containsKey("T2#1"));
    assertEquals(4, jsonObject.size());//from   w w w.  j  ava  2  s.c  o  m
}

From source file:functionaltests.RestSchedulerTagTest.java

@Test
public void testTaskResultSerializedvalueByTag() throws Exception {
    HttpResponse response = sendRequest(
            "jobs/" + submittedJobId + "/tasks/tag/LOOP-T2-1/result/serializedvalue");
    JSONObject jsonObject = toJsonObject(response);

    System.out.println(jsonObject.toJSONString());

    assertTrue(jsonObject.containsKey("T1#1"));
    assertTrue(jsonObject.containsKey("Print1#1"));
    assertTrue(jsonObject.containsKey("Print2#1"));
    assertTrue(jsonObject.containsKey("T2#1"));
    assertEquals(4, jsonObject.size());//from  w  w w.j a va 2  s.  co m
}

From source file:com.fujitsu.dc.test.utils.UserDataUtils.java

/**
 * NP???????.//from ww w.  ja v  a2 s.com
 * @param token (???)
 * @param code ??
 * @param body 
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param entityType 
 * @param id ?__id
 * @param navPropName NavigationProperty??("_"??)
 * @return ?
 */
public static TResponse createViaNPAnyAuthSchema(String token, JSONObject body, String cell, String box,
        String collection, String entityType, String id, String navPropName, int code) {
    TResponse res = Http.request("box/odatacol/createNP-anyAuthSchema.txt").with("cell", cell).with("box", box)
            .with("collection", collection).with("entityType", entityType).with("id", id)
            .with("navPropName", "_" + navPropName).with("accept", MediaType.APPLICATION_JSON)
            .with("contentType", MediaType.APPLICATION_JSON).with("token", token)
            .with("body", body.toJSONString()).returns().statusCode(code).debug();
    return res;
}

From source file:com.shootoff.session.io.JSONSessionWriter.java

@SuppressWarnings("unchecked")
@Override//from   w w w.java 2s . c om
public void visitEnd() {
    JSONObject session = new JSONObject();
    session.put("cameras", cameras);

    Writer file = null;

    try {
        file = new OutputStreamWriter(new FileOutputStream(sessionFile), "UTF-8");
        file.write(session.toJSONString());
        file.flush();
    } catch (IOException e) {
        logger.error("Error writing JSON session", e);
    } finally {
        try {
            if (file != null)
                file.close();
        } catch (IOException e) {
            logger.error("Error closing JSON session", e);
        }

    }
}

From source file:hoot.services.controllers.ingest.BasemapResourceTest.java

@Test
@Category(UnitTest.class)
public void TestgetBasemapList() throws Exception {
    BasemapResource mapRes = new BasemapResource();
    File f = new File(mapRes._tileServerPath + "/BASEMAP/TestMap");
    FileUtils.forceMkdir(f);/*from   w ww. ja  v  a2 s  .co m*/

    JSONObject cont = new JSONObject();
    cont.put("jobid", "123-456-789");
    cont.put("path", "/projects/hoot/ingest/processed/BASEMAP/TestMap");

    File file = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap.enabled");
    FileUtils.writeStringToFile(file, cont.toJSONString());

    File f2 = new File(mapRes._tileServerPath + "/BASEMAP/TestMap2");
    FileUtils.forceMkdir(f2);

    File file2 = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap2.enabled");
    FileUtils.writeStringToFile(file2, cont.toJSONString());

    JSONArray res = mapRes._getBasemapList();
    boolean found = false;
    for (Object oMap : res) {
        JSONObject map = (JSONObject) oMap;
        if (map.get("name").toString().equals("TestMap")) {
            found = true;
            break;
        }
    }
    org.junit.Assert.assertTrue(found);
    FileUtils.forceDelete(f);
    FileUtils.forceDelete(f2);
}

From source file:eu.edisonproject.rest.FolderWatcherRunnable.java

private File convertCSVJsonFile(String csvFile, String outputJsonFile) throws IOException {
    File f = new File(csvFile);
    if (f.exists()) {
        Map<String, Double> map = new HashMap<>();
        try (BufferedReader br = new BufferedReader(new FileReader(f))) {
            String line;//  w w  w .j  av  a2 s .c o  m
            while ((line = br.readLine()) != null) {
                String[] kv = line.split(",");
                map.put(kv[0], Double.valueOf(kv[1]));
            }
        }

        File jsonFile = new File(outputJsonFile);
        JSONObject jo = new JSONObject(map);
        try (PrintWriter out = new PrintWriter(jsonFile)) {
            out.print(jo.toJSONString());
        }
        return jsonFile;
    }
    return null;
}

From source file:org.opencastproject.adminui.endpoint.UsersSettingsEndpointTest.java

@Test
public void testGetSignatureExpectsOK() throws ParseException, IOException {
    JSONObject actual = (JSONObject) parser.parse(given().log().all().expect().statusCode(HttpStatus.SC_OK)
            .contentType(ContentType.JSON).when().get(rt.host("/signature")).asString());
    System.out.println(actual.toJSONString());
}

From source file:com.conwet.silbops.model.SubscriptionTest.java

@Test
public void shouldToJSONStringWithExists() throws ParseException {

    String string = "{\"id\":\"\",\"contextFunction\": {},\"constraints\": {"
            + "\"attr:str\":[{\"exists\":\"\"}]}}";
    JSONObject json = (JSONObject) new JSONParser().parse(string);
    Subscription attrExists = new Subscription().constrain("attr", Type.STRING).exists().subscription();

    assertThat(attrExists.toJSONString()).isEqualTo(json.toJSONString());
}

From source file:eu.edisonproject.rest.FolderWatcherRunnable.java

private File convertMRResultToJsonFile(String mrPartPath) throws IOException {
    File parent = new File(mrPartPath).getParentFile();
    Map<String, Map<String, Double>> map = new HashMap<>();
    Map<String, Double> catSimMap;
    try (BufferedReader br = new BufferedReader(new FileReader(mrPartPath))) {
        String line;// www  .  j  a v  a  2s.co m
        while ((line = br.readLine()) != null) {
            String[] kv = line.split("\t");
            String fileName = kv[0];
            String cat = kv[1];
            String sim = kv[2];
            catSimMap = map.get(fileName);
            if (catSimMap == null) {
                catSimMap = new HashMap<>();
            }
            catSimMap.put(cat, Double.valueOf(sim));
            map.put(fileName, catSimMap);
        }
    }

    //    JSONArray ja = new JSONArray();
    //    for (String fname : map.keySet()) {
    //      Map<String, Double> catMap = map.get(fname);
    //      JSONObject jo = new JSONObject(catMap);
    //      ja.add(jo);
    //    }
    File jsonFile = new File(parent.getAbsoluteFile() + File.separator + JSON_FILE_NAME);
    JSONObject jo = new JSONObject(map);
    try (PrintWriter out = new PrintWriter(jsonFile)) {
        out.print(jo.toJSONString());
    }
    return jsonFile;
}

From source file:jQuery.PRIMO.RestAPI.java

/**
 * Get version./*from  w w w.ja  v a 2 s .co m*/
 *
 * @return version
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/version")
public Response getVersion() {
    JSONObject versionData = new JSONObject();
    versionData.put("version", Version.VERSION_NUMBER);
    //versionData.put("build", Version.BUILD_TIME);
    versionData.put("description", "jQuery.PRIMO web services");
    return Response.status(200).entity(versionData.toJSONString()).build();
}