Example usage for org.json.simple JSONObject put

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

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.walmartlabs.mupd8.application.Config.java

@SuppressWarnings("unchecked")
private static void apply(JSONObject destination, JSONObject source) {
    for (Object k : source.keySet()) {
        String key = (String) k;
        if (destination.containsKey(key) && (destination.get(key) != null)
                && (destination.get(key) instanceof JSONObject) && (source.get(key) instanceof JSONObject)) {
            try {
                JSONObject subDestination = (JSONObject) destination.get(key);
                JSONObject subSource = (JSONObject) source.get(key);
                apply(subDestination, subSource);
            } catch (ClassCastException e) {
                throw new ClassCastException("Config: cannot override key " + key
                        + " with new value because it is not a JSON object");
            }/*from  w  w  w .  j a  va  2  s .  c  om*/
        } else {
            destination.put(key, source.get(key));
        }
    }
}

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

@SuppressWarnings("unchecked")
@Override/*from  w  w w  . j  a  va2s  .  c om*/
public HttpEntity createDocument(Filter filter) {

    JSONObject propertyObject = new JSONObject();
    propertyObject.put("value", filter.getValue());
    Integer user = filter.getUser() != null ? filter.getUser().getId() : null;
    propertyObject.put("user", user);

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

From source file:MyCpuListener.java

@SuppressWarnings("unchecked")
public void cpuEvent(CpuEvent event) {

    obj.put("timestamp", event.getEventTime());
    JSONObject cpu = new JSONObject();
    cpu.put("process", event.getProcessUse());
    cpu.put("system", event.getSystemUse());
    obj.put("cpu", cpu);

    IndexResponse response = eSC.getClient().prepareIndex(eSC.getIndex(), "cpu").setSource(obj.toJSONString())
            .get();// w w w.java 2 s. c  o  m
}

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

@SuppressWarnings("unchecked")
@Override/*from w ww .j a  v  a 2 s. com*/
public HttpEntity createDocument(Ruleset ruleset) {

    JSONObject rulesetObject = new JSONObject();
    rulesetObject.put("title", ruleset.getTitle());
    rulesetObject.put("file", ruleset.getFile());
    rulesetObject.put("orderMetadataByRuleset", ruleset.isOrderMetadataByRuleset());
    rulesetObject.put("fileContent", "");

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

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

@SuppressWarnings("unchecked")
@Override/*from   w ww  . j  a va  2s . com*/
public HttpEntity createDocument(UserGroup userGroup) {

    JSONObject userGroupObject = new JSONObject();
    userGroupObject.put("title", userGroup.getTitle());
    userGroupObject.put("permission", userGroup.getPermission());
    userGroupObject.put("users", addObjectRelation(userGroup.getUsers()));

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

From source file:JSON.WriteQuestionnaireJSON.java

public void buildJSON(String quesString, String quesid) {
    JSONObject ques = new JSONObject();
    ques.put("name", quesid);
    ques.put("question", quesString);
    JSONArray options = new JSONArray();
    options.add("High");
    options.add("Medium");
    options.add("Low");
    ques.put("options", options);

    questions.add(ques);//from   ww  w . j a  v a  2 s . co  m
}

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

@SuppressWarnings("unchecked")
@Override/* w w  w. j  a  v a  2  s.c  o  m*/
public HttpEntity createDocument(Template template) {

    JSONObject templateObject = new JSONObject();
    templateObject.put("origin", template.getOrigin());
    Integer process = template.getProcess() != null ? template.getProcess().getId() : null;
    templateObject.put("process", process);
    templateObject.put("properties", addObjectRelation(template.getProperties()));

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

From source file:backend.FriendRequestConfirmation.java

@Override
public JSONObject jsonize() {
    JSONObject o = new JSONObject();
    o.put("sender", m_receiver.get_user_id());
    o.put("sender_alias", m_receiver.get_alias());
    o.put("receiver", m_sender.get_user_id());
    o.put("receiver_alias", m_sender.get_alias());
    return o;/*from   www  .  j a va2s .  c  o m*/
}

From source file:io.personium.client.http.PersoniumBatchRespose.java

/**
 * This method returns the response body in JSON format.
 * @return JSONObject/*www . j a v a 2  s . co  m*/
 * @throws DaoException Exception thrown
 */
@SuppressWarnings("unchecked")
public final JSONObject bodyAsJson() throws DaoException {
    JSONObject results = new JSONObject();
    results.put("results", new JSONObject());
    JSONObject d = new JSONObject();
    d.put("d", results);
    return d;
}

From source file:com.github.sourjson.translat.def.ClassTranslater.java

@SuppressWarnings("unchecked")
@Override/*from w w  w  .  ja va  2 s  . co  m*/
public @CheckForNull JSONObject serialize(Class obj, Type typeOnServer, AnnotatedElement el,
        @CheckForNull Object enclosing, SourJson json, double version) {
    JSONObject ret = new JSONObject();
    ret.put("name", obj.getName());
    return ret;
}