Package com.google.gson

Examples of com.google.gson.JsonArray


      List list = List.class.cast(payload);
      for (Object o : list) {
         checkArgument(o instanceof ServerInfo, "this binder is only valid for List<ServerInfo>!");
      }
      Iterable<ServerInfo> serverInfoList = (Iterable<ServerInfo>) payload;
      JsonArray serversJsonArray = new JsonArray();

      for (ServerInfo serverInfo : serverInfoList) {
         JsonObject driveObject = createServerInfoRequestToJson.apply(serverInfo);
         serversJsonArray.add(driveObject);
      }

      JsonObject json = new JsonObject();
      json.add("objects", serversJsonArray);
View Full Code Here


      List list = List.class.cast(payload);
      for (Object o : list) {
         checkArgument(o instanceof Tag, "this binder is only valid for List<Tag>!");
      }
      Iterable<Tag> tags = (Iterable<Tag>) payload;
      JsonArray tagJsonArray = new JsonArray();

      for (Tag tag : tags) {
         JsonObject driveObject = tagJsonObjectFunction.apply(tag);
         tagJsonArray.add(driveObject);
      }

      JsonObject json = new JsonObject();
      json.add("objects", tagJsonArray);
View Full Code Here

      for (Object o : list) {
         checkArgument(o instanceof CreateSubscriptionRequest,
               "this binder is only valid for List<CreateSubscriptionRequest>!");
      }
      List<CreateSubscriptionRequest> createSubscriptionRequests = (List<CreateSubscriptionRequest>) input;
      JsonArray subscriptionsJsonArray = new JsonArray();

      for (CreateSubscriptionRequest createSubscriptionRequest : createSubscriptionRequests) {
         JsonObject sunbscriptionRequestObject = subscriptionRequestJsonObjectFunction.apply(createSubscriptionRequest);
         subscriptionsJsonArray.add(sunbscriptionRequestObject);
      }

      JsonObject json = new JsonObject();
      json.add("objects", subscriptionsJsonArray);
View Full Code Here

      List list = List.class.cast(input);
      for (Object o : list) {
         checkArgument(o instanceof FirewallPolicy, "this binder is only valid for List<FirewallPolicy>!");
      }
      List<FirewallPolicy> firewallPolicies = (List<FirewallPolicy>) input;
      JsonArray firewalsJsonArray = new JsonArray();

      for (FirewallPolicy firewallPolicy : firewallPolicies) {
         JsonObject firewallObject = policyJsonObjectFunction.apply(firewallPolicy);
         firewalsJsonArray.add(firewallObject);
      }

      JsonObject json = new JsonObject();
      json.add("objects", firewalsJsonArray);
View Full Code Here

      List list = List.class.cast(payload);
      for (Object o : list) {
         checkArgument(o instanceof String, "this binder is only valid for List<String>!");
      }
      Iterable<String> uuids = (Iterable<String>) payload;
      JsonArray uuidJsonArray = new JsonArray();
      JsonObject json = new JsonObject();

      for (String uuid : uuids) {
         JsonObject uuidObject = new JsonObject();
         uuidObject.addProperty("uuid", uuid);
         uuidJsonArray.add(uuidObject);
      }

      json.add("objects", uuidJsonArray);
      request.setPayload(json.toString());
      request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON);
View Full Code Here

      List list = List.class.cast(payload);
      for (Object o : list) {
         checkArgument(o instanceof DriveInfo, "this binder is only valid for List<DriveInfo>!");
      }
      List<DriveInfo> drivesList = (List<DriveInfo>) payload;
      JsonArray drivesJsonArray = new JsonArray();

      for (DriveInfo drive : drivesList) {
         JsonObject driveObject = createDriveRequestJson.apply(drive);
         drivesJsonArray.add(driveObject);
      }

      JsonObject json = new JsonObject();
      json.add("objects", drivesJsonArray);
View Full Code Here

        depOptions, inputs);
    assertTrue(results.isEmpty());
  }

  public void testToJson() throws JsonParseException {
    JsonArray modules = graph.toJson();
    assertEquals(6, modules.size());
    for (int i = 0; i < modules.size(); i++) {
      JsonObject m = modules.get(i).getAsJsonObject();
      assertNotNull(m.get("name"));
      assertNotNull(m.get("dependencies"));
      assertNotNull(m.get("transitive-dependencies"));
      assertNotNull(m.get("inputs"));
    }
    JsonObject m = modules.get(3).getAsJsonObject();
    assertEquals("D", m.get("name").getAsString());
    assertEquals("[\"B\"]", m.get("dependencies").getAsJsonArray().toString());
    assertEquals(2,
        m.get("transitive-dependencies").getAsJsonArray().size());
    assertEquals("[]", m.get("inputs").getAsJsonArray().toString());
View Full Code Here

   * - "transitive-dependencies" (list of module names, deepest first)
   * - "inputs" (list of file names)
   * @return List of module JSONObjects.
   */
  JsonArray toJson() {
    JsonArray modules = new JsonArray();
    for (JSModule module : getAllModules()) {
      JsonObject node = new JsonObject();
      try {
        node.add("name", new JsonPrimitive(module.getName()));
        JsonArray deps = new JsonArray();
        node.add("dependencies", deps);
        for (JSModule m : module.getDependencies()) {
          deps.add(new JsonPrimitive(m.getName()));
        }
        JsonArray transitiveDeps = new JsonArray();
        node.add("transitive-dependencies", transitiveDeps);
        for (JSModule m : getTransitiveDepsDeepestFirst(module)) {
          transitiveDeps.add(new JsonPrimitive(m.getName()));
        }
        JsonArray inputs = new JsonArray();
        node.add("inputs", inputs);
        for (CompilerInput input : module.getInputs()) {
          inputs.add(new JsonPrimitive(
              input.getSourceFile().getOriginalPath()));
        }
        modules.add(node);
      } catch (JsonParseException e) {
        Throwables.propagate(e);
View Full Code Here

    // Get all 'functions' as JsonObjects from the file and add them as a
    // list
    JsonElement functions = JsonUtils.findElement(moduleJsonObject, "functions");
    if (functions != null) {
      if (functions.isJsonArray()) {
        JsonArray requests_array = functions.getAsJsonArray();
        for (JsonElement requestElement : requests_array) {
          if (requestElement.isJsonObject()) {
            JsonObject request = requestElement.getAsJsonObject();
            requestElements.add(request);
          }
View Full Code Here

            queue.add(member.getValue());
          }
        }

      } else if (element.isJsonArray()) {
        JsonArray array = element.getAsJsonArray();
        for (JsonElement array_element : array) {
          queue.add(array_element);
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.