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:com.conwet.silbops.model.SubscriptionTest.java

@Test
public void shouldToJSONString() throws ParseException {

    // uses a JSON object to be independent of keys order.
    String string = "{\"id\":\"\",\"contextFunction\": {},\"constraints\": {"
            + "\"symbol:str\":[{\"=\":\"GOOG\"}]," + "\"value:long\":[{\">\": 10}]}}";
    JSONObject json = (JSONObject) new JSONParser().parse(string);
    assertThat(subscription.toJSONString()).isEqualTo(json.toJSONString());
}

From source file:com.netflix.dyno.connectionpool.impl.MonitorConsoleResource.java

@SuppressWarnings("unchecked")
@Path("/topology/{cpName}")
@GET//from w w  w  . j  a v a  2  s .com
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public String getConnectionPoolToplogy(@PathParam("cpName") String cpName) {

    TokenPoolTopology topology = MonitorConsole.getInstance().getTopology(cpName);
    if (topology == null) {
        return "Not Found: " + cpName;
    }

    ConcurrentHashMap<String, List<TokenStatus>> map = topology.getAllTokens();

    JSONObject json = new JSONObject();

    for (String rack : map.keySet()) {
        List<TokenStatus> tokens = map.get(rack);
        json.put(rack, getTokenStatusMap(tokens));
    }
    return json.toJSONString();
}

From source file:ElasticSearchConnection.java

public void putMappings(String fileName, String type) {

    JSONParser parser = new JSONParser();

    try {/*  w  ww . j a  v a  2  s  .  co m*/
        Object obj = parser
                .parse(new InputStreamReader(ElasticSearchConnection.class.getResourceAsStream(fileName)));

        JSONObject jsonObject = (JSONObject) obj;
        PutMappingResponse response = getClient().admin().indices().preparePutMapping(getIndex()).setType(type)
                .setSource(jsonObject.toJSONString()).execute().actionGet();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }

}

From source file:com.appzone.sim.services.handlers.AppRegistrationServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String infoRequest = request.getParameter(KEY_INFO_REQUEST);

    if (infoRequest != null) {
        Application application = Application.getApplication();
        JSONObject json = new JSONObject();
        json.put(JSON_KEY_URL, application.getUrl());
        json.put(JSON_KEY_USERNAME, application.getUsername());
        json.put(JSON_KEY_PASSWORD, application.getPassword());

        return json.toJSONString();
    } else {/*  w  w w.  j  a  va  2s .  c om*/
        String url = request.getParameter(KEY_URL);
        String username = request.getParameter(KEY_USERNAME);
        String password = request.getParameter(KEY_PASSWORD);

        logger.info("configuring application with: " + url + " :: {} :: {}", username, password);

        Application.configure(url, username, password);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_RESULT, true);

        return json.toJSONString();
    }
}

From source file:ch.simas.jtoggl.Task.java

public Task(String jsonString) {
    JSONObject object = (JSONObject) JSONValue.parse(jsonString);
    this.id = (Long) object.get("id");
    this.name = (String) object.get("name");
    this.estimated_seconds = (Long) object.get("estimated_seconds");
    this.is_active = (Boolean) object.get("active");

    JSONObject workspaceObject = (JSONObject) object.get("workspace");
    if (workspaceObject != null) {
        this.workspace = new Workspace(workspaceObject.toJSONString());
    }/*w w  w  . ja v  a2  s  . c  o  m*/
    JSONObject projectObject = (JSONObject) object.get("project");
    if (projectObject != null) {
        this.project = new Project(projectObject.toJSONString());
    }
    JSONObject userObject = (JSONObject) object.get("user");
    if (userObject != null) {
        this.user = new User(userObject.toJSONString());
    }
}

From source file:com.aerothai.database.servicemethod.ServicemethodResource.java

/**
 * Retrieves representation of an instance of com.aerothai.ServicemethodResource
 * @return an instance of java.lang.String
 *//*from  ww  w.ja v a2  s .c  o m*/
@GET
@Produces("application/json")
public String listServicemethodAt(@PathParam("id") int id) {
    String response = null;

    System.out.println("List Servicemethod At ID");
    try {
        JSONObject servicemethodData = null;
        ServicemethodService servicemethodService = new ServicemethodService();
        servicemethodData = servicemethodService.GetServicemethodAt(id);

        response = servicemethodData.toJSONString();
    } catch (Exception e) {
        System.out.println("error");
    }

    return response;
}

From source file:eg.nileu.cis.nilestore.interfaces.file.UploadResults.java

/**
 * Dumpto json./*from   www. j  a v  a  2s  .com*/
 * 
 * @param webAddress
 *            the web address
 * @return the string
 */
@SuppressWarnings("unchecked")
public String dumptoJson(String webAddress) {
    JSONObject obj = new JSONObject();
    obj.put("downloadLink", String.format(webAddress, uri.toString()));
    obj.put("cap", uri.toString());
    obj.put("times", times);
    return obj.toJSONString();
}

From source file:com.zaizi.alfresco.spouts.AlfrescoSpout.java

@Override
public void nextTuple() {
    if (listIterator != null && listIterator.hasNext()) {
        // Returning node by node
        Map<String, Object> item = listIterator.next();
        JSONObject jsonObject = new JSONObject();

        for (Map.Entry<String, Object> mapEntry : item.entrySet()) {
            jsonObject.put(mapEntry.getKey(), mapEntry.getValue());
        }//  w  ww.  j av  a 2  s . c o  m

        _collector.emit(new Values(jsonObject.toJSONString()));

        listIterator.remove();
    } else {
        // Fetch changed nodes if list is empty.
        Utils.sleep(1000);
        fetchNodes();
    }
}

From source file:org.kitodo.data.elasticsearch.index.type.WorkpieceType.java

@SuppressWarnings("unchecked")
@Override/*from w  ww .  ja  v  a 2  s .c  o  m*/
public HttpEntity createDocument(Workpiece workpiece) {

    JSONObject workpieceObject = new JSONObject();
    Integer process = workpiece.getProcess() != null ? workpiece.getProcess().getId() : null;
    workpieceObject.put("process", process);
    workpieceObject.put("properties", addObjectRelation(workpiece.getProperties()));

    return new NStringEntity(workpieceObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:com.wso2mobile.mam.packageExtractor.ZipFileReading.java

public String readAndroidManifestFile(String filePath) {
    String xml = "";
    try {/*from   www.  j a v a 2 s  .  c  o m*/
        ZipInputStream stream = new ZipInputStream(new FileInputStream(filePath));
        try {
            ZipEntry entry;
            while ((entry = stream.getNextEntry()) != null) {
                if (entry.getName().equals("AndroidManifest.xml")) {
                    StringBuilder builder = new StringBuilder();
                    xml = AndroidXMLParsing.decompressXML(IOUtils.toByteArray(stream));
                }
            }
        } finally {
            stream.close();
        }
        Document doc = loadXMLFromString(xml);
        doc.getDocumentElement().normalize();
        JSONObject obj = new JSONObject();
        obj.put("version", doc.getDocumentElement().getAttribute("versionName"));
        obj.put("package", doc.getDocumentElement().getAttribute("package"));
        xml = obj.toJSONString();
    } catch (Exception e) {
        xml = "Exception occured " + e;
    }
    return xml;
}