Example usage for com.google.gson JsonObject JsonObject

List of usage examples for com.google.gson JsonObject JsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonObject JsonObject.

Prototype

JsonObject

Source Link

Usage

From source file:cf.adriantodt.David.modules.rest.GetController.java

License:LGPL

public static JsonElement toJson(Guild g) {
    JsonObject guild = new JsonObject();
    guild.addProperty("id", g.getId());
    guild.addProperty("name", g.getName());
    guild.addProperty("avatar", g.getIconUrl());
    guild.addProperty("vip", GuildModule.fromDiscord(g).getFlag("vip"));
    return guild;
}

From source file:cf.adriantodt.David.modules.rest.WebInterfaceHelper.java

License:LGPL

public static JsonObject object() {
    JsonObject object = new JsonObject();
    object.addProperty("fine", true);
    return object;
}

From source file:ch.cern.db.flume.JSONEvent.java

License:GNU General Public License

public JSONEvent() {
    headers = new HashMap<String, String>();
    json = new JsonObject();
}

From source file:ch.cern.db.flume.source.deserializer.RecoveryManagerDeserializer.java

License:GNU General Public License

private JsonArray recoveryManagerReportsToJSON(List<RecoveryManagerReport> recoveryManagerReports) {
    JsonArray array = new JsonArray();

    for (RecoveryManagerReport recoveryManagerReport : recoveryManagerReports) {
        JsonObject element = new JsonObject();

        element.addProperty("startingTime", JSONUtils.to(recoveryManagerReport.getStartingTime()));

        List<Pair<Integer, String>> rmans = recoveryManagerReport.getRMANs();
        element.add("RMAN-", toJSON(rmans));
        element.add("ORA-", toJSON(recoveryManagerReport.getORAs()));

        element.addProperty("finishTime", JSONUtils.to(recoveryManagerReport.getFinishTime()));
        element.addProperty("returnCode", recoveryManagerReport.getReturnCode());
        element.addProperty("status", rmans.size() == 0 ? "Successful" : "Failed");

        array.add(element);//from  w  w w. ja v  a 2 s . c  o m
    }

    return array;
}

From source file:ch.cern.db.flume.source.deserializer.RecoveryManagerDeserializer.java

License:GNU General Public License

private JsonArray toJSON(List<Pair<Integer, String>> list) {
    JsonArray array = new JsonArray();

    for (Pair<Integer, String> rmanError : list) {
        JsonObject element = new JsonObject();

        element.addProperty("id", rmanError.getFirst());
        element.addProperty("message", rmanError.getSecond());

        array.add(element);/*from  w  w  w . j  a v a2  s. c om*/
    }

    return array;
}

From source file:ch.cyberduck.core.openstack.SwiftSegmentService.java

License:Open Source License

/**
 * Create the appropriate manifest structure for a static large object (SLO).
 * The number of object segments is limited to a configurable amount, default 1000. Each segment,
 * except for the final one, must be at least 1 megabyte (configurable).
 *
 * @param objects Ordered list of segments
 * @return ETag returned by the simple upload total size of segment uploaded path of segment
 *///from   ww w  .ja  va 2 s .co  m
public String manifest(final String container, final List<StorageObject> objects) {
    JsonArray manifestSLO = new JsonArray();
    for (StorageObject s : objects) {
        JsonObject segmentJSON = new JsonObject();
        // this is the container and object name in the format {container-name}/{object-name}
        segmentJSON.addProperty("path", String.format("/%s/%s", container, s.getName()));
        // MD5 checksum of the content of the segment object
        segmentJSON.addProperty("etag", s.getMd5sum());
        segmentJSON.addProperty("size_bytes", s.getSize());
        manifestSLO.add(segmentJSON);
    }
    return manifestSLO.toString();
}

From source file:ch.eitchnet.csvrestendpoint.marshaller.CsvDataToHeaderJsonMarshaller.java

License:Apache License

@Override
public JsonObject marshall(CSVParser csvParser) {

    JsonObject root = new JsonObject();
    root.addProperty("msg", "-");

    JsonArray data = new JsonArray();

    Set<Entry<String, Integer>> header = csvParser.getHeaderMap().entrySet();
    for (Entry<String, Integer> entry : header) {
        data.add(new JsonPrimitive(entry.getKey()));
    }//ww  w . j  a v  a 2 s  .  c o  m

    root.add("data", data);

    return root;
}

From source file:ch.eitchnet.csvrestendpoint.marshaller.CsvDataToJsonMarshaller.java

License:Apache License

@Override
public JsonObject marshall(CSVParser csvParser) {

    // validate any references to column names
    Map<String, Integer> headerMap = csvParser.getHeaderMap();
    validate(headerMap);//from   w  w w.ja v a2 s .c o m

    // filter
    List<CSVRecord> allRecords = new ArrayList<>();
    long dataSetSize = 0;
    for (CSVRecord record : csvParser) {
        dataSetSize++;
        if (isSelected(headerMap, record))
            allRecords.add(record);
    }

    // sort
    if (StringHelper.isNotEmpty(sortBy)) {
        Integer columnIndex = headerMap.get(sortBy);
        if (this.ascending)
            allRecords.sort((r1, r2) -> r1.get(columnIndex).compareTo(r2.get(columnIndex)));
        else
            allRecords.sort((r1, r2) -> r2.get(columnIndex).compareTo(r1.get(columnIndex)));
    }

    // paging
    Paging<CSVRecord> paging = Paging.asPage(allRecords, this.pageSize, this.page);

    // get page
    List<CSVRecord> page = paging.getPage();

    // build JSON response
    JsonObject root = new JsonObject();
    root.addProperty("msg", "-");
    root.addProperty("draw", this.draw);
    root.addProperty("dataSetSize", dataSetSize);
    root.addProperty("nrOfElements", paging.getNrOfElements());

    if (StringHelper.isNotEmpty(sortBy))
        root.addProperty("sortBy", this.sortBy);
    root.addProperty("ascending", this.ascending);
    root.addProperty("nrOfPages", paging.getNrOfPages());
    root.addProperty("pageSize", paging.getPageSize());
    root.addProperty("page", paging.getPageToReturn());

    // prune any unwanted columns
    if (!this.returnFields.isEmpty()) {
        headerMap.keySet().retainAll(this.returnFields);
    }

    // add items
    JsonArray data = new JsonArray();
    for (CSVRecord record : page) {
        JsonObject element = new JsonObject();
        for (Entry<String, Integer> entry : headerMap.entrySet()) {
            String column = entry.getKey();
            String value = record.get(entry.getValue());
            element.addProperty(column, value);
        }
        data.add(element);
    }
    root.add("data", data);

    return root;
}

From source file:ch.eitchnet.csvrestendpoint.marshaller.CsvNamesToJsonMarshaller.java

License:Apache License

public JsonObject marshall(List<String> names) {

    JsonObject root = new JsonObject();
    root.addProperty("msg", "-");

    JsonArray data = new JsonArray();

    for (String name : names) {
        data.add(new JsonPrimitive(name));
    }/* ww w  .  j  a v  a2s.  c  om*/

    root.add("data", data);

    return root;
}

From source file:ch.epfl.leb.sass.models.fluorophores.internal.DefaultFluorophore.java

License:Open Source License

@Override
public JsonElement serialize(DefaultFluorophore src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject result = new JsonObject();
    result.add("id", new JsonPrimitive(src.getId()));
    result.add("x", new JsonPrimitive(src.x));
    result.add("y", new JsonPrimitive(src.y));
    result.add("z", new JsonPrimitive(src.z));
    result.add("currentState", new JsonPrimitive(src.getCurrentState()));
    result.add("maxPhotonsPerFrame", new JsonPrimitive(src.getSignal()));
    result.add("bleached", new JsonPrimitive(src.isBleached()));
    result.add("emitting", new JsonPrimitive(src.isOn()));
    result.add("onTime", new JsonPrimitive(src.getOnTimeThisFrame()));
    result.add("photonsEmittedLastFrame", new JsonPrimitive(src.getPhotonsThisFrame()));
    return result;
}