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.stratio.deep.es.utils.UtilES.java

/**
 * converts from an entity class with deep's anotations to JSONObject.
 *
 * @param t   an instance of an object of type T to convert to JSONObject.
 * @param <T> the type of the object to convert.
 * @return the provided object converted to JSONObject.
 * @throws IllegalAccessException//from   ww w  . ja va2s.co m
 * @throws InstantiationException
 * @throws InvocationTargetException
 */
public static <T> JSONObject getJsonFromObject(T t)
        throws IllegalAccessException, InstantiationException, InvocationTargetException {
    Field[] fields = AnnotationUtils.filterDeepFields(t.getClass());

    JSONObject json = new JSONObject();

    for (Field field : fields) {
        Method method = Utils.findGetter(field.getName(), t.getClass());
        Object object = method.invoke(t);
        if (object != null) {
            if (Collection.class.isAssignableFrom(field.getType())) {
                Collection c = (Collection) object;
                Iterator iterator = c.iterator();
                List<JSONObject> innerJsonList = new ArrayList<>();

                while (iterator.hasNext()) {
                    innerJsonList.add(getJsonFromObject((IDeepType) iterator.next()));
                }
                json.put(AnnotationUtils.deepFieldName(field), innerJsonList);
            } else if (IDeepType.class.isAssignableFrom(field.getType())) {
                json.put(AnnotationUtils.deepFieldName(field), getJsonFromObject((IDeepType) object));
            } else {
                json.put(AnnotationUtils.deepFieldName(field), object);
            }
        }
    }

    return json;
}

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

@SuppressWarnings("unchecked")
@Override//w  w  w. j a  va 2  s  . co m
public HttpEntity createDocument(Task task) {
    JSONObject taskObject = new JSONObject();
    taskObject.put("title", task.getTitle());
    taskObject.put("priority", task.getPriority());
    taskObject.put("ordering", task.getOrdering());
    Integer processingStatus = task.getProcessingStatusEnum() != null
            ? task.getProcessingStatusEnum().getValue()
            : null;
    taskObject.put("processingStatus", processingStatus);
    String processingTime = task.getProcessingTime() != null ? formatDate(task.getProcessingTime()) : null;
    taskObject.put("processingTime", processingTime);
    String processingBegin = task.getProcessingBegin() != null ? formatDate(task.getProcessingBegin()) : null;
    taskObject.put("processingBegin", processingBegin);
    String processingEnd = task.getProcessingEnd() != null ? formatDate(task.getProcessingEnd()) : null;
    taskObject.put("processingEnd", processingEnd);
    taskObject.put("homeDirectory", String.valueOf(task.getHomeDirectory()));
    taskObject.put("typeMetadata", String.valueOf(task.isTypeMetadata()));
    taskObject.put("typeAutomatic", String.valueOf(task.isTypeAutomatic()));
    taskObject.put("typeImportFileUpload", String.valueOf(task.isTypeImportFileUpload()));
    taskObject.put("typeExportRussian", String.valueOf(task.isTypeExportRussian()));
    taskObject.put("typeImagesRead", String.valueOf(task.isTypeImagesRead()));
    taskObject.put("typeImagesWrite", String.valueOf(task.isTypeImagesWrite()));
    taskObject.put("typeModuleName", task.getTypeModuleName());
    taskObject.put("batchStep", String.valueOf(task.isBatchStep()));
    Integer processingUser = task.getProcessingUser() != null ? task.getProcessingUser().getId() : null;
    taskObject.put("processingUser", processingUser);
    Integer process = task.getProcess() != null ? task.getProcess().getId() : null;
    taskObject.put("process", process);
    taskObject.put("users", addObjectRelation(task.getUsers()));
    taskObject.put("userGroups", addObjectRelation(task.getUserGroups()));

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

From source file:com.conwet.silbops.msg.SubscribeMsg.java

@Override
@SuppressWarnings("unchecked")
public JSONObject getPayloadAsJSON() {

    JSONObject json = new JSONObject();
    json.put("subscription", subscription.toJSON());

    return json;//  ww  w .  j  a v  a2s .c  om
}

From source file:de.hstsoft.sdeep.Configuration.java

@SuppressWarnings("unchecked")
public void save() {
    JSONObject jsonObject = new JSONObject();

    jsonObject.put(PREF_SAVEGAME_PATH, saveGamePath);
    jsonObject.put(PREF_AUTOREFRESH, autorefresh);

    try {/*from  w w  w.j ava  2s  .c  o m*/
        String jsonString = jsonObject.toJSONString();
        FileWriter fileWriter = new FileWriter(configFile);
        fileWriter.append(jsonString);
        fileWriter.flush();
        fileWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:co.mcme.animations.actions.ChainAnimationAction.java

@Override
public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    JSONObject data = new JSONObject();
    data.put("frame", frame);
    data.put("target", targetName);
    result.put("chain_animation", data);
    return result;
}

From source file:com.dubture.twig.core.model.Test.java

@SuppressWarnings("unchecked")
@Override//from ww w .  ja v a2 s . c o m
public String getMetadata() {

    JSONObject data = new JSONObject();
    data.put(PHPCLASS, phpClass);
    data.put(DOC, getDocString());
    data.put(INTERNAL, internalFunction);

    return data.toString();
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.SquareZone.java

@SuppressWarnings("unchecked")
@Override/* www.ja  v  a2  s  . c  o  m*/
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "square");

    JSONObject l = new JSONObject();
    l.put("lat", new Double(maxLatitude));
    l.put("lon", new Double(minLongitude));
    o.put("leftTop", l);

    JSONObject r = new JSONObject();
    r.put("lat", new Double(minLatitude));
    r.put("lon", new Double(maxLongitude));
    o.put("rightBottom", r);

    JSONObject d = new JSONObject();
    d.put("lat", new Double(getDepotPosition().getLatitude()));
    d.put("lon", new Double(getDepotPosition().getLongitude()));
    o.put("depot", d);

    return null;
}

From source file:biomine.bmvis2.pipeline.sources.FileGraphSource.java

public JSONObject toJSON() {
    JSONObject ret = new JSONObject();
    ret.put("file", name);
    return ret;
}

From source file:co.mcme.animations.triggers.AlwaysActiveTrigger.java

@Override
public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    JSONObject dummy = new JSONObject();
    dummy.put("dummy", "dummy");
    result.put("always_active", dummy);
    return result;
}

From source file:com.conwet.silbops.msg.NotifyMsg.java

@Override
@SuppressWarnings("unchecked")
public JSONObject getPayloadAsJSON() {

    JSONObject json = new JSONObject();
    json.put("notification", notification.toJSON());

    return json;// w w w  . j  a va  2 s .  c  om
}