Example usage for com.google.gson JsonArray JsonArray

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

Introduction

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

Prototype

public JsonArray() 

Source Link

Document

Creates an empty JsonArray.

Usage

From source file:com.google.cloud.solutions.sampleapps.orchestration.orchestrator.server.InstanceStatusServlet.java

License:Open Source License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
    JsonArray jsonAr = new JsonArray();
    Map<String, String> gceIpsAndInstanceNames = orchestrator.getGceIpsAndInstanceNames();
    resp.setContentType("application/json");
    resp.setHeader("Cache-Control", "no-cache");
    for (String gceIp : gceIpsAndInstanceNames.keySet()) {
        try {//from  ww w .j  a v a  2 s  .c  o m
            // Query each instance for its status/load.
            URL url = new URL("http://" + gceIp + ":8080/StatusPublisher/status");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            GceStats gceStats = gson.fromJson(reader, GceStats.class);
            reader.close();
            JsonObject instanceElem = new JsonObject();
            instanceElem.addProperty("instanceName", gceIpsAndInstanceNames.get(gceIp));
            instanceElem.addProperty("status", gson.toJson(gceStats));
            jsonAr.add(instanceElem);
        } catch (MalformedURLException e) {
            logger.warning("Malformed URL: " + e);
        } catch (IOException e) {
            logger.warning("Can't open stream: " + e);
        }
    }
    PrintWriter writer = resp.getWriter();
    writer.println(gson.toJson(jsonAr));
}

From source file:com.google.dart.server.generated.types.AnalysisErrorFixes.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.add("error", error.toJson());
    JsonArray jsonArrayFixes = new JsonArray();
    for (SourceChange elt : fixes) {
        jsonArrayFixes.add(elt.toJson());
    }//w  ww.j  a v  a  2 s.  c o m
    jsonObject.add("fixes", jsonArrayFixes);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.ChangeContentOverlay.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("type", type);
    JsonArray jsonArrayEdits = new JsonArray();
    for (SourceEdit elt : edits) {
        jsonArrayEdits.add(elt.toJson());
    }/*ww w  .  j a v  a  2  s. c  o m*/
    jsonObject.add("edits", jsonArrayEdits);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.CompletionSuggestion.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("kind", kind);
    jsonObject.addProperty("relevance", relevance);
    jsonObject.addProperty("completion", completion);
    jsonObject.addProperty("selectionOffset", selectionOffset);
    jsonObject.addProperty("selectionLength", selectionLength);
    jsonObject.addProperty("isDeprecated", isDeprecated);
    jsonObject.addProperty("isPotential", isPotential);
    if (docSummary != null) {
        jsonObject.addProperty("docSummary", docSummary);
    }// w ww.jav  a 2 s.  co m
    if (docComplete != null) {
        jsonObject.addProperty("docComplete", docComplete);
    }
    if (declaringType != null) {
        jsonObject.addProperty("declaringType", declaringType);
    }
    if (element != null) {
        jsonObject.add("element", element.toJson());
    }
    if (returnType != null) {
        jsonObject.addProperty("returnType", returnType);
    }
    if (parameterNames != null) {
        JsonArray jsonArrayParameterNames = new JsonArray();
        for (String elt : parameterNames) {
            jsonArrayParameterNames.add(new JsonPrimitive(elt));
        }
        jsonObject.add("parameterNames", jsonArrayParameterNames);
    }
    if (parameterTypes != null) {
        JsonArray jsonArrayParameterTypes = new JsonArray();
        for (String elt : parameterTypes) {
            jsonArrayParameterTypes.add(new JsonPrimitive(elt));
        }
        jsonObject.add("parameterTypes", jsonArrayParameterTypes);
    }
    if (requiredParameterCount != null) {
        jsonObject.addProperty("requiredParameterCount", requiredParameterCount);
    }
    if (hasNamedParameters != null) {
        jsonObject.addProperty("hasNamedParameters", hasNamedParameters);
    }
    if (parameterName != null) {
        jsonObject.addProperty("parameterName", parameterName);
    }
    if (parameterType != null) {
        jsonObject.addProperty("parameterType", parameterType);
    }
    if (importUri != null) {
        jsonObject.addProperty("importUri", importUri);
    }
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.ExtractLocalVariableFeedback.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    JsonArray jsonArrayNames = new JsonArray();
    for (String elt : names) {
        jsonArrayNames.add(new JsonPrimitive(elt));
    }//from  w ww.j av  a  2  s.c o m
    jsonObject.add("names", jsonArrayNames);
    JsonArray jsonArrayOffsets = new JsonArray();
    for (int elt : offsets) {
        jsonArrayOffsets.add(new JsonPrimitive(elt));
    }
    jsonObject.add("offsets", jsonArrayOffsets);
    JsonArray jsonArrayLengths = new JsonArray();
    for (int elt : lengths) {
        jsonArrayLengths.add(new JsonPrimitive(elt));
    }
    jsonObject.add("lengths", jsonArrayLengths);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.ExtractMethodFeedback.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("offset", offset);
    jsonObject.addProperty("length", length);
    jsonObject.addProperty("returnType", returnType);
    JsonArray jsonArrayNames = new JsonArray();
    for (String elt : names) {
        jsonArrayNames.add(new JsonPrimitive(elt));
    }/* ww  w  . j  a  v  a2s .c o  m*/
    jsonObject.add("names", jsonArrayNames);
    jsonObject.addProperty("canCreateGetter", canCreateGetter);
    JsonArray jsonArrayParameters = new JsonArray();
    for (RefactoringMethodParameter elt : parameters) {
        jsonArrayParameters.add(elt.toJson());
    }
    jsonObject.add("parameters", jsonArrayParameters);
    JsonArray jsonArrayOffsets = new JsonArray();
    for (int elt : offsets) {
        jsonArrayOffsets.add(new JsonPrimitive(elt));
    }
    jsonObject.add("offsets", jsonArrayOffsets);
    JsonArray jsonArrayLengths = new JsonArray();
    for (int elt : lengths) {
        jsonArrayLengths.add(new JsonPrimitive(elt));
    }
    jsonObject.add("lengths", jsonArrayLengths);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.ExtractMethodOptions.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("returnType", returnType);
    jsonObject.addProperty("createGetter", createGetter);
    jsonObject.addProperty("name", name);
    JsonArray jsonArrayParameters = new JsonArray();
    for (RefactoringMethodParameter elt : parameters) {
        jsonArrayParameters.add(elt.toJson());
    }//from w  ww .jav a  2s. c o m
    jsonObject.add("parameters", jsonArrayParameters);
    jsonObject.addProperty("extractAll", extractAll);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.LinkedEditGroup.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    JsonArray jsonArrayPositions = new JsonArray();
    for (Position elt : positions) {
        jsonArrayPositions.add(elt.toJson());
    }/*from w w  w .  j a va2 s  . c om*/
    jsonObject.add("positions", jsonArrayPositions);
    jsonObject.addProperty("length", length);
    JsonArray jsonArraySuggestions = new JsonArray();
    for (LinkedEditSuggestion elt : suggestions) {
        jsonArraySuggestions.add(elt.toJson());
    }
    jsonObject.add("suggestions", jsonArraySuggestions);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.NavigationRegion.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("offset", offset);
    jsonObject.addProperty("length", length);
    JsonArray jsonArrayTargets = new JsonArray();
    for (int elt : targets) {
        jsonArrayTargets.add(new JsonPrimitive(elt));
    }//w  ww  .  j a v  a2s . c o m
    jsonObject.add("targets", jsonArrayTargets);
    return jsonObject;
}

From source file:com.google.dart.server.generated.types.Occurrences.java

License:Open Source License

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.add("element", element.toJson());
    JsonArray jsonArrayOffsets = new JsonArray();
    for (int elt : offsets) {
        jsonArrayOffsets.add(new JsonPrimitive(elt));
    }//from   ww  w  .j a v  a  2s . co  m
    jsonObject.add("offsets", jsonArrayOffsets);
    jsonObject.addProperty("length", length);
    return jsonObject;
}