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:HttpClient.HttpCalendarClient.java

private JSONObject send_request_response(JSONObject req, String operation) {
    //oggetto da rimpire e restituire
    JSONObject res = null;//from   w w  w .  j  ava2  s.c  om
    //imposto il "contenitore" della risposta JSON
    CloseableHttpResponse response1 = null;
    //creo una richiesta di tipo POSTal WS
    HttpPost r_post = new HttpPost(url + operation);
    //imposto l'HEADER della richiesta a JSON
    r_post.addHeader(new BasicHeader("Content-Type", "application/json"));
    //Creo l'entita' da inserire nella richiesta, ipostandone come contenuto il JSON
    StringEntity param = new StringEntity(req.toJSONString(), "UTF8");
    param.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    r_post.setEntity(param);
    //EFFETTUO LA RICHIESTA
    try {
        //EFFETTUO la richiesta ed attendo la risposta dal WS
        response1 = httpclient.execute(r_post);
        if (response1.getEntity() != null) //converto lo stream ottenuto in un oggetto JSON
        {
            res = convertStreamToJson(response1.getEntity().getContent());
        }

    } catch (IOException ex) {
        Logger.getLogger(HttpCalendarClient.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            response1.close();
        } catch (IOException ex) {
            Logger.getLogger(HttpCalendarClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return res;
}

From source file:com.modeln.batam.connector.wrapper.Step.java

@SuppressWarnings("unchecked")
public String toJSONString() {
    JSONObject obj = new JSONObject();
    obj.put("order", order);
    obj.put("name", name);
    obj.put("start_date", startDate == null ? null : String.valueOf(startDate.getTime()));
    obj.put("end_date", endDate == null ? null : String.valueOf(endDate.getTime()));
    obj.put("input", input);
    obj.put("expected", expected);
    obj.put("output", output);
    obj.put("status", status);
    obj.put("error", error);
    obj.put("isCustomFormatEnabled", isCustomFormatEnabled);
    obj.put("customFormat", customFormat);
    obj.put("customEntry", customEntry);

    return obj.toJSONString();
}

From source file:com.nubits.nubot.tasks.strategy.PriceMonitorTriggerTask.java

public void setOutputPath(String outputPath) {
    this.outputPath = outputPath;
    this.jsonFile = this.outputPath.replace(".csv", ".json");
    //create json file if it doesn't already exist
    File json = new File(this.jsonFile);
    if (!json.exists()) {
        JSONObject history = new JSONObject();
        JSONArray wall_shifts = new JSONArray();
        history.put("wall_shifts", wall_shifts);
        FileSystem.writeToFile(history.toJSONString(), this.jsonFile, true);
    }//from   w  w w .j  a v a2s  .  c om
}

From source file:net.matthewauld.racetrack.server.WrSQL.java

@SuppressWarnings("unchecked")
public String getJSONClasses(String query) throws SQLException {
    connect();/*from w  w w .  j  a  va  2s . com*/
    st = con.createStatement();
    rs = st.executeQuery(query);

    JSONObject json = new JSONObject();
    JSONArray classes = new JSONArray();
    while (rs.next()) {
        JSONObject classJSON = new JSONObject();
        classJSON.put("id", rs.getInt("id"));
        classJSON.put("title", rs.getString("title"));
        classes.add(classJSON);
    }

    if (classes.size() == 0) {
        json.put("classes", null);
    } else {
        json.put("classes", classes);
    }

    return json.toJSONString();
}

From source file:com.fujitsu.dc.test.jersey.cell.MessageMethodNotAllowTest.java

private TResponse mergeRequest(String path, String ifMatch, JSONObject updateReqBody) {
    return Http.request("cell/merge.txt").with("cell", Setup.TEST_CELL1).with("path", path)
            .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
            .with("ifMatch", ifMatch).with("token", DcCoreConfig.getMasterToken())
            .with("body", updateReqBody.toJSONString()).returns().debug();
}

From source file:com.modeln.batam.connector.wrapper.ReportEntry.java

@SuppressWarnings("unchecked")
public String toJSONString() {
    JSONObject obj = new JSONObject();
    obj.put("id", id);
    obj.put("name", name);
    obj.put("build_id", buildId);
    obj.put("build_name", buildName);
    obj.put("description", description);
    obj.put("start_date", startDate == null ? null : String.valueOf(startDate.getTime()));
    obj.put("end_date", endDate == null ? null : String.valueOf(endDate.getTime()));
    obj.put("status", status);
    obj.put("logs", logs);
    obj.put("isCustomFormatEnabled", isCustomFormatEnabled);
    obj.put("customFormat", customFormat);
    obj.put("customEntry", customEntry);

    return obj.toJSONString();
}

From source file:mml.handler.post.MMLPostResourceHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException {
    try {//w  w w  .  j  av a 2  s. c o  m
        if (ServletFileUpload.isMultipartContent(request)) {
            parseImportParams(request);
            for (int i = 0; i < files.size(); i++) {
                String style = files.get(i);
                JSONObject jDoc = new JSONObject();
                jDoc.put(JSONKeys.BODY, style);
                if (this.author != null)
                    jDoc.put(JSONKeys.AUTHOR, this.author);
                if (this.title != null)
                    jDoc.put(JSONKeys.TITLE, this.title);
                if (this.style != null)
                    jDoc.put(JSONKeys.STYLE, this.style);
                if (this.format != null)
                    jDoc.put(JSONKeys.FORMAT, this.format);
                if (this.section != null)
                    jDoc.put(JSONKeys.SECTION, this.section);
                if (this.version1 != null)
                    jDoc.put(JSONKeys.VERSION1, this.version1);
                Connector.getConnection().putToDb(database, docid, jDoc.toJSONString());
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new MMLException(e);
    }
}

From source file:io.personium.test.jersey.cell.MessageMethodNotAllowTest.java

private TResponse mergeRequest(String path, String ifMatch, JSONObject updateReqBody) {
    return Http.request("cell/merge.txt").with("cell", Setup.TEST_CELL1).with("path", path)
            .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
            .with("ifMatch", ifMatch).with("token", PersoniumUnitConfig.getMasterToken())
            .with("body", updateReqBody.toJSONString()).returns().debug();
}

From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java

@SuppressWarnings("unchecked")
protected String getLocationJSON(Location loc) {
    JSONObject data = new JSONObject();
    // world//  w  w  w  .  ja  v  a2 s . c o m
    data.put("world", loc.getWorld().getName());
    // x, y, z
    data.put("x", String.valueOf(loc.getX()));
    data.put("y", String.valueOf(loc.getY()));
    data.put("z", String.valueOf(loc.getZ()));
    // pitch, yaw
    data.put("pitch", String.valueOf(loc.getPitch()));
    data.put("yaw", String.valueOf(loc.getYaw()));
    return data.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override//from w  ww  . j a v  a2 s .  com
public HttpEntity createDocument(User user) {

    JSONObject userObject = new JSONObject();
    userObject.put("name", user.getName());
    userObject.put("surname", user.getSurname());
    userObject.put("login", user.getLogin());
    userObject.put("ldapLogin", user.getLdapLogin());
    userObject.put("active", String.valueOf(user.isActive()));
    userObject.put("location", user.getLocation());
    userObject.put("metadataLanguage", user.getMetadataLanguage());
    userObject.put("userGroups", addObjectRelation(user.getUserGroups()));
    userObject.put("filters", addObjectRelation(user.getFilters()));
    userObject.put("projects", addObjectRelation(user.getProjects()));
    userObject.put("processingTasks", addObjectRelation(user.getProcessingTasks()));
    userObject.put("tasks", addObjectRelation(user.getTasks()));

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