Examples of toJsonTree()


Examples of com.google.gson.Gson.toJsonTree()

   void testToJson() {
      StorageMetadata storage = StorageMetadata.builder().creationDate(Calendar.getInstance().getTime()).name("file.txt")
                                                         .uri("https://somehost/file.txt")
                                                         .build();
      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(storage);
      assertNotNull(json);
      assertEquals("file.txt", json.getAsJsonObject().get("name").getAsString());
      assertEquals("https://somehost/file.txt", json.getAsJsonObject().get("uri").getAsString());
   }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

                                           .is64Bit(true)
                                           .build())
                                   .build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(image);
      assertNotNull(json);
      assertEquals("1", json.getAsJsonObject().get("id").getAsString());
      assertEquals("My image", json.getAsJsonObject().get("name").getAsString());
      assertEquals("UBUNTU", json.getAsJsonObject().getAsJsonObject("operatingSystem").get("family").getAsString());
   }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

                                   .processors(ImmutableList.of(Processor.builder().cores(4).speed(2).build()))
                                   .volumes(ImmutableList.of(Volume.builder().device("/dev/tst1").size(100f).bootDevice(true).build()))
                                   .build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(hardware);
      assertNotNull(json);
      assertEquals("test-hardware-profile", json.getAsJsonObject().get("id").getAsString());
      assertEquals("4.0", json.getAsJsonObject().get("processors").getAsJsonArray().get(0).getAsJsonObject().get("cores").getAsString());
      assertEquals("2.0", json.getAsJsonObject().get("processors").getAsJsonArray().get(0).getAsJsonObject().get("speed").getAsString());
   }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

                                                                .build())

                                                        .build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(nodeMetadata);
      assertNotNull(json);
      assertEquals("1", json.getAsJsonObject().get("id").getAsString());
      assertEquals("testnode-1", json.getAsJsonObject().get("name").getAsString());
      assertEquals("root", json.getAsJsonObject().getAsJsonObject("defaultCredentials").get("username").getAsString());
      assertEquals("password1", json.getAsJsonObject().getAsJsonObject("defaultCredentials").get("password").getAsString());
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

    JsonObject recipeAsJSON = new JsonObject();

    if (!attribs.isEmpty()) {
      JsonObject jsonAttribs = new JsonObject();
      for (Map.Entry<String, Object> entry : attribs.entrySet()) {
        jsonAttribs.add(entry.getKey(), gson.toJsonTree(entry.getValue()));
      }

      // add the attribs
      recipeAsJSON.add(cookbook, jsonAttribs);
    }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

    }

    // add the recipe
    recipeAsJSON.add(
        "run_list",
        gson.toJsonTree(new String[] { "recipe[" + cookbook
            + (recipe != null ? ("::" + recipe) : "") + "]" }));

    return gson.toJson(recipeAsJSON);

  }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

                                           .is64Bit(true)
                                           .build())
                                   .build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(image);
      assertNotNull(json);
      assertEquals("1", json.getAsJsonObject().get("id").getAsString());
      assertEquals("My image", json.getAsJsonObject().get("name").getAsString());
      assertEquals("UBUNTU", json.getAsJsonObject().getAsJsonObject("operatingSystem").get("family").getAsString());
   }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

   void testToJson() {
      StorageMetadata storage = StorageMetadata.builder().creationDate(Calendar.getInstance().getTime()).name("file.txt")
                                                         .uri("https://somehost/file.txt")
                                                         .build();
      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(storage);
      assertNotNull(json);
      assertEquals("file.txt", json.getAsJsonObject().get("name").getAsString());
      assertEquals("https://somehost/file.txt", json.getAsJsonObject().get("uri").getAsString());
   }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

                                   .processors(ImmutableList.of(Processor.builder().cores(4).speed(2).build()))
                                   .volumes(ImmutableList.of(Volume.builder().device("/dev/tst1").size(100f).bootDevice(true).build()))
                                   .build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(hardware);
      assertNotNull(json);
      assertEquals("test-hardware-profile", json.getAsJsonObject().get("id").getAsString());
      assertEquals("4.0", json.getAsJsonObject().get("processors").getAsJsonArray().get(0).getAsJsonObject().get("cores").getAsString());
      assertEquals("2.0", json.getAsJsonObject().get("processors").getAsJsonArray().get(0).getAsJsonObject().get("speed").getAsString());
   }
View Full Code Here

Examples of com.google.gson.Gson.toJsonTree()

                                                                .build())

                                                        .build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(nodeMetadata);
      assertNotNull(json);
      assertEquals("1", json.getAsJsonObject().get("id").getAsString());
      assertEquals("testnode-1", json.getAsJsonObject().get("name").getAsString());
      assertEquals("root", json.getAsJsonObject().getAsJsonObject("defaultCredentials").get("username").getAsString());
      assertEquals("password1", json.getAsJsonObject().getAsJsonObject("defaultCredentials").get("password").getAsString());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.