Package com.google.gson

Examples of com.google.gson.JsonArray


      if (input.getVncPassword() != null) {
         serverObject.addProperty("vnc_password", input.getVncPassword());
      }

      if (input.getNics() != null) {
         JsonArray nics = new JsonArray();

         for (NIC nic : input.getNics()) {
            JsonObject nicObject = new JsonObject();

            if (nic.getFirewallPolicy() != null) {
               nicObject.addProperty("firewall_policy", nic.getFirewallPolicy().getUuid());
            }

            if (nic.getVlan() != null) {
               nicObject.addProperty("vlan", nic.getVlan().getUuid());
            } else if (nic.getIpV4Configuration() != null) {
               nicObject.add("ip_v4_conf", ipConfigurationToJsonObject(nic.getIpV4Configuration()));

               if (nic.getModel() != null) {
                  nicObject.addProperty("model", nic.getModel().value());
               }
               if (nic.getMac() != null) {
                  nicObject.addProperty("mac", nic.getMac());
               }
            } else if (nic.getIpV6Configuration() != null) {
               nicObject.add("ip_v6_conf", ipConfigurationToJsonObject(nic.getIpV6Configuration()));

               if (nic.getModel() != null) {
                  nicObject.addProperty("model", nic.getModel().value());
               }
               if (nic.getMac() != null) {
                  nicObject.addProperty("mac", nic.getMac());
               }
            }

            nics.add(nicObject);
         }

         serverObject.add("nics", nics);
      }

      if (input.getDrives() != null) {
         JsonArray serverDrives = new JsonArray();

         for (ServerDrive serverDrive : input.getDrives()) {
            JsonObject driveObject = new JsonObject();
            driveObject.addProperty("boot_order", serverDrive.getBootOrder());

            if (serverDrive.getDeviceChannel() != null) {
               driveObject.addProperty("dev_channel", serverDrive.getDeviceChannel());
            }

            if (serverDrive.getDeviceEmulationType() != null) {
               driveObject.addProperty("device", serverDrive.getDeviceEmulationType().value());
            }

            if (serverDrive.getDriveUuid() != null) {
               driveObject.addProperty("drive", serverDrive.getDriveUuid());
            } else if (serverDrive.getDrive() != null) {
               driveObject.addProperty("drive", serverDrive.getDrive().getUuid());
            }

            serverDrives.add(driveObject);
         }
         serverObject.add("drives", serverDrives);
      }

      return serverObject;
View Full Code Here


      if (input.getMeta() != null) {
         firewallObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
      }

      if (input.getRules() != null) {
         JsonArray rulesArray = new JsonArray();

         for (FirewallRule rule : input.getRules()) {
            JsonObject ruleObject = new JsonObject();

            if (rule.getAction() != null) {
               ruleObject.addProperty("action", rule.getAction().value());
            }

            if (rule.getComment() != null) {
               ruleObject.addProperty("comment", rule.getComment());
            }

            if (rule.getDirection() != null) {
               ruleObject.addProperty("direction", rule.getDirection().value());
            }

            if (rule.getDestinationIp() != null) {
               ruleObject.addProperty("dst_ip", rule.getDestinationIp());
            }

            if (rule.getDestinationPort() != null) {
               ruleObject.addProperty("dst_port", rule.getDestinationPort());
            }

            if (rule.getIpProtocol() != null) {
               ruleObject.addProperty("ip_proto", rule.getIpProtocol().toString());
            }

            if (rule.getSourceIp() != null) {
               ruleObject.addProperty("src_ip", rule.getSourceIp());
            }

            if (rule.getSourcePort() != null) {
               ruleObject.addProperty("src_port", rule.getSourcePort());
            }

            rulesArray.add(ruleObject);
         }

         firewallObject.add("rules", rulesArray);
      }
      return firewallObject;
View Full Code Here

      JsonObject metaObject = new JsonObject();
      metaObject.addProperty("description", "A full server with description");

      expected.add("meta", metaObject);
      expected.add("requirements", new JsonArray());

      JsonArray tagsArray = new JsonArray();
      tagsArray.add(new JsonPrimitive("tag_uuid_1"));
      tagsArray.add(new JsonPrimitive("tag_uuid_2"));
      expected.add("tags", tagsArray);
      expected.addProperty("vnc_password", "tester");

      JsonObject nicJson = new JsonObject();

      JsonObject ipv4ConfObject = new JsonObject();
      ipv4ConfObject.addProperty("conf", "dhcp");
      nicJson.add("ip_v4_conf", ipv4ConfObject);
      nicJson.addProperty("model", "virtio");
      nicJson.addProperty("mac", "22:a7:a0:0d:43:48");

      JsonArray nicsArray = new JsonArray();
      nicsArray.add(nicJson);

      expected.add("nics", nicsArray);

      JsonArray drivesArray = new JsonArray();
      JsonObject driveJson1 = new JsonObject();
      driveJson1.addProperty("boot_order", 0);
      driveJson1.addProperty("dev_channel", "0:0");
      driveJson1.addProperty("device", "ide");
      driveJson1.addProperty("drive", "ae78e68c-9daa-4471-8878-0bb87fa80260");

      JsonObject driveJson2 = new JsonObject();
      driveJson2.addProperty("boot_order", 1);
      driveJson2.addProperty("dev_channel", "0:0");
      driveJson2.addProperty("device", "virtio");
      driveJson2.addProperty("drive", "22826af4-d6c8-4d39-bd41-9cea86df2976");

      drivesArray.add(driveJson1);
      drivesArray.add(driveJson2);

      expected.add("drives", drivesArray);
   }
View Full Code Here

      metaObject.addProperty("description", "test tag");

      expected.add("meta", metaObject);
      expected.addProperty("name", "TagCreatedWithResource");

      JsonArray resourcesArray = new JsonArray();
      resourcesArray.add(new JsonPrimitive("96537817-f4b6-496b-a861-e74192d3ccb0"));
      resourcesArray.add(new JsonPrimitive("61bcc398-c034-42f1-81c9-f6d7f62c4ea0"));
      resourcesArray.add(new JsonPrimitive("3610d935-514a-4552-acf3-a40dd0a5f961"));
      resourcesArray.add(new JsonPrimitive("185.12.6.183"));

      expected.add("resources", resourcesArray);
   }
View Full Code Here

      rule5Object.addProperty("comment", "Drop any traffic, to the VM with destination port not between 1-1024");
      rule5Object.addProperty("direction", "in");
      rule5Object.addProperty("dst_port", "!1:1024");
      rule5Object.addProperty("ip_proto", "tcp");

      JsonArray rulesArray = new JsonArray();
      rulesArray.add(rule1Object);
      rulesArray.add(rule2Object);
      rulesArray.add(rule3Object);
      rulesArray.add(rule4Object);
      rulesArray.add(rule5Object);

      expected.add("rules", rulesArray);
   }
View Full Code Here

*/
public class VectorAdapter implements JsonDeserializer<Vector> {

    @Override
    public Vector deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        JsonArray jsonArray = json.getAsJsonArray();
        if (jsonArray.size() != 3) {
            throw new JsonParseException("Expected array of 3 length for Vector");
        }

        double x = jsonArray.get(0).getAsDouble();
        double y = jsonArray.get(1).getAsDouble();
        double z = jsonArray.get(2).getAsDouble();

        return new Vector(x, y, z);
    }
View Full Code Here

        System.out,
        new BasePaths(new File("")),
        2 * 60 * 60,
        Collections.<FileInfo>emptyList(),
        Collections.<FileInfo>emptyList(),
        new JsonArray())).getInstance(ActionRunner.class);
  }
View Full Code Here

        System.out,
        new BasePaths(new File("")),
        2 * 60 * 60,
        Collections.<FileInfo>emptyList(),
        Collections.<FileInfo>emptyList(),
        new JsonArray())).getInstance(ActionRunner.class);
  }
View Full Code Here

    createServer(new TestListener());
    server.start();
    JsonObject entry = new JsonObject();
    entry.addProperty("matcher", "/*");
    entry.addProperty("server", "http://localhost:8888/");
    JsonArray gatewayConfig = new JsonArray();
    gatewayConfig.add(entry);
    final HttpServer client = new HttpServer(new NullStopWatch());
    client.postJson("http://localhost:4224/jstd/gateway", gatewayConfig);
    SocketConnector connector = new SocketConnector();
    connector.setPort(8888);
    org.mortbay.jetty.Server dummy = new org.mortbay.jetty.Server();
    dummy.addConnector(connector);
    Context context = new Context(dummy, "/", Context.SESSIONS);
    DummyServlet servlet = new DummyServlet();
    context.addServlet(new ServletHolder(servlet), "/");
    dummy.start();
    final PrintStream out = System.out;
    final int N = 100;
    Thread[] threads = new Thread[2*N];
    final AtomicInteger a = new AtomicInteger(0);
    for (int i = 0; i < 2*N; ++i) {
      final int j = i;
      threads[i] = new Thread() {
        @Override public void run() {
          try {
            if (j % 2 == 0) {
              client.postJson("http://localhost:4224/asdf", new JsonArray());
            } else {
              HttpURLConnection connection = (HttpURLConnection)
                  new URL("http://localhost:4224/asdf").openConnection();
              // TODO(rdionne): Add Content-Type to prevent failure case after
              // gateway is rewritten.
View Full Code Here

            System.out,
            new BasePaths(new File(".")),
            2 * 60 * 60,
            Collections.<FileInfo>emptyList(),
            Collections.<FileInfo>emptyList(),
            new JsonArray());

    final Injector injector = Guice.createInjector(Lists.newArrayList(coverage, printStream,
        new DebugModule(false), jsTestDriverModule));

    injector.getInstance(ActionRunner.class);
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.