Package com.google.gson

Examples of com.google.gson.JsonObject


     * status (initialized).
     * @throws Exception if failed
     */
    @Test
    public void status_initialized() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "initialized");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);

View Full Code Here


  @Override
  public JsonElement serialize(Point arg0, Type arg1,
      JsonSerializationContext arg2) {
   
    JsonObject point = new JsonObject();
    point.addProperty("x",  arg0.getX());
    point.addProperty("y",  arg0.getY());
 
    return point;
  }
View Full Code Here

*/
@Singleton
public class TagToJson implements Function<Tag, JsonObject> {
   @Override
   public JsonObject apply(@Nullable Tag input) {
      JsonObject jsonTag = new JsonObject();

      if (input.getName() != null) {
         jsonTag.addProperty("name", input.getName());
      }

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

      if (input.getResources() != null && input.getResources().size() != 0) {
         JsonArray uuidsArray = new JsonArray();

         for (TagResource tagResource : input.getResources()) {
            uuidsArray.add(new JsonPrimitive(tagResource.getUuid()));
         }

         jsonTag.add("resources", uuidsArray);
      }

      return jsonTag;
   }
View Full Code Here

*/
@Singleton
public class ServerInfoToJson implements Function<ServerInfo, JsonObject> {
   @Override
   public JsonObject apply(ServerInfo input) {
      JsonObject serverObject = new JsonObject();

      if (input.getName() != null) {
         serverObject.addProperty("name", input.getName());
      }

      if (input.getCpu() > 0) {
         serverObject.addProperty("cpu", input.getCpu());
      }

      if (input.getMemory() != null) {
         serverObject.addProperty("mem", input.getMemory().toString());
      }

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

      if (input.getRequirements() != null) {
         serverObject.add("requirements", new JsonParser().parse(new Gson().toJson(input.getRequirements())));
      }

      if (input.getTags() != null) {
         serverObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags())));
      }

      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);
View Full Code Here

   /**
    * A name-value pair to associate with the container as metadata.
    */
   public CreateCDMIObjectOptions metadata(Map<String, String> metadata) {
      JsonObject jsonObjectMetadata = new JsonObject();
      if (metadata != null) {
         for (Entry<String, String> entry : metadata.entrySet()) {
            jsonObjectMetadata.addProperty(entry.getKey(), entry.getValue());
         }
      }
      jsonObjectBody.add("metadata", jsonObjectMetadata);
      this.payload = jsonObjectBody.toString();
      return this;
View Full Code Here

      return serverObject;
   }

   private JsonObject ipConfigurationToJsonObject(IPConfiguration ipConfiguration) {
      JsonObject ipConfObject = new JsonObject();
      if (ipConfiguration.getConfigurationType() != null) {
         ipConfObject.addProperty("conf", ipConfiguration.getConfigurationType().value());
      }
      if (ipConfiguration.getIp() != null) {
         ipConfObject.addProperty("ip", ipConfiguration.getIp().getUuid());
      }
      return ipConfObject;
   }
View Full Code Here

   public JsonObject apply(@Nullable ProfileInfo input) {
      if (input == null) {
         return null;
      }

      JsonObject profileJson = new JsonObject();

      if (input.getAddress() != null) {
         profileJson.addProperty("address", input.getAddress());
      }

      if (input.getBankReference() != null) {
         profileJson.addProperty("bank_reference", input.getBankReference());
      }

      if (input.getCompany() != null) {
         profileJson.addProperty("company", input.getCompany());
      }

      if (input.getCountry() != null) {
         profileJson.addProperty("country", input.getCountry());
      }

      if (input.getEmail() != null) {
         profileJson.addProperty("email", input.getEmail());
      }

      if (input.getFirstName() != null) {
         profileJson.addProperty("first_name", input.getFirstName());
      }

      if (input.getLastName() != null) {
         profileJson.addProperty("last_name", input.getLastName());
      }

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

      if (input.getMyNotes() != null) {
         profileJson.addProperty("my_notes", input.getMyNotes());
      }

      if (input.getNickname() != null) {
         profileJson.addProperty("nickname", input.getNickname());
      }

      if (input.getPhone() != null) {
         profileJson.addProperty("phone", input.getPhone());
      }

      if (input.getPostcode() != null) {
         profileJson.addProperty("postcode", input.getPostcode());
      }

      if (input.getTitle() != null) {
         profileJson.addProperty("title", input.getTitle());
      }

      if (input.getTown() != null) {
         profileJson.addProperty("town", input.getTown());
      }

      return profileJson;
   }
View Full Code Here

*/
@Singleton
public class FirewallPolicyToJson implements Function<FirewallPolicy, JsonObject> {
   @Override
   public JsonObject apply(@Nullable FirewallPolicy input) {
      JsonObject firewallObject = new JsonObject();

      if (input.getName() != null) {
         firewallObject.addProperty("name", input.getName());
      }

      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);
         }

View Full Code Here

      expected.addProperty("name", "test_acc_full_server");
      expected.addProperty("cpu", 1000);
      expected.addProperty("mem", "268435456");

      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

                  .build())
            .tags(new ArrayList<Tag>())
            .uuid("185.12.6.183")
            .build();

      expected = new JsonObject();

      JsonObject metaObject = new JsonObject();
      metaObject.addProperty("description", "test ip");
      metaObject.addProperty("test_key_1", "test_value_1");
      metaObject.addProperty("test_key_2", "test_value_2");

      expected.add("meta", metaObject);
   }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonObject

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.