Examples of toJsonTree()


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

      ProviderMetadata providerMetadata = ProviderMetadata.builder()
                                                          .id("test-provider").defaultProperties(props)
                                                          .name("My test provider").build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(providerMetadata);
      assertNotNull(json);
      assertEquals("test-provider", json.getAsJsonObject().get("id").getAsString());
      assertEquals("value1", json.getAsJsonObject().getAsJsonObject("defaultProperties").get("key1").getAsString());
      assertEquals("value2", json.getAsJsonObject().getAsJsonObject("defaultProperties").get("key2").getAsString());
      assertEquals("value3", json.getAsJsonObject().getAsJsonObject("defaultProperties").get("key3").getAsString());
View Full Code Here

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

   @Test
   void testToJson() {
      Location location = Location.builder().id("region-1a").scope("ZONE").parentId("region-1").iso3166Codes(ImmutableSet.of("IE")).build();
      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(location);
      assertNotNull(json);
      assertEquals("region-1a", json.getAsJsonObject().get("id").getAsString());
      assertEquals("ZONE", json.getAsJsonObject().get("scope").getAsString());
      assertEquals("region-1", json.getAsJsonObject().get("parentId").getAsString());
      assertEquals("IE", json.getAsJsonObject().get("iso3166Codes").getAsJsonArray().get(0).getAsString());
View Full Code Here

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

   @Test
   void testToJson() {
      Context context = Context.builder().name("my-context").identity("me").providerId("test-provider").build();
      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(context);
      assertNotNull(json);
      assertEquals("my-context", json.getAsJsonObject().get("name").getAsString());
      assertEquals("me", json.getAsJsonObject().get("identity").getAsString());
      assertEquals("test-provider", json.getAsJsonObject().get("providerId").getAsString());
   }
View Full Code Here

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

                                           .credentialName("credential")
                                           .documentation("http://somehost.org/doc")
                                           .defaultProperties(props).build();

      Gson gson = new GsonBuilder().create();
      JsonElement json = gson.toJsonTree(apiMetadata);
      assertNotNull(json);
      assertEquals("test-api", json.getAsJsonObject().get("id").getAsString());
      assertEquals("value1", json.getAsJsonObject().getAsJsonObject("defaultProperties").get("key1").getAsString());
      assertEquals("value2", json.getAsJsonObject().getAsJsonObject("defaultProperties").get("key2").getAsString());
      assertEquals("value3", json.getAsJsonObject().getAsJsonObject("defaultProperties").get("key3").getAsString());
View Full Code Here

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

   * @return execution result
   */
  public <R> R execute(MailChimpMethod<R> method) throws IOException, MailChimpException {
    final Gson gson = MailChimpGsonFactory.createGson();

    JsonElement result = execute(buildUrl(method), gson.toJsonTree(method));
    if(result.isJsonObject()) {
      JsonElement error = result.getAsJsonObject().get("error");   
      if(error != null) {
        JsonElement code = result.getAsJsonObject().get("code");
        throw new MailChimpException(code.getAsInt(), error.getAsString());
View Full Code Here

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

   * @return execution result
   */
  public <R> R execute(MailChimpMethod<R> method) throws IOException, MailChimpException {
    final Gson gson = MailChimpGsonFactory.createGson();

    JsonElement result = execute(buildUrl(method), gson.toJsonTree(method));
    if(result.isJsonObject()) {
      JsonElement error = result.getAsJsonObject().get("error");   
      if(error != null) {
        JsonElement code = result.getAsJsonObject().get("code");
        throw new MailChimpException(code.getAsInt(), error.getAsString());
View Full Code Here

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

        DateTime.class, new GsonDateTimeSerializer());
    if (serializeNullFields) {
      gsonBuilder.serializeNulls();
    }
    Gson gson = gsonBuilder.create();
    return gson.toJsonTree(object);
  }

  /**
   * Returns the "pretty print" {@link String} version of a
   * {@link JsonElement}
View Full Code Here

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

        public boolean shouldSkipClass(Class<?> clazz) {
          return false;
        }
      }).create();

      JsonElement tree = gson.toJsonTree(fResults);
      JsonObject jo = new JsonObject();
        jo.add("autocomplete", tree);
      resp.getWriter().write(jo.toString());
        }
        catch (Exception e)
View Full Code Here

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

            }

            subDTO.setItems(result);
            service.storeDTOs(req, suuid, subDTO);
            List<Map<String, Object>> dto = getLightResultList(result);
            JsonElement tree = json.toJsonTree(dto);
            JsonObject jo = new JsonObject();
            jo.add("result", tree);
            resp.getWriter().write(jo.toString());

        }
View Full Code Here

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

            }

            subDTO.setItems(result);
            service.storeDTOs(req, suuid, subDTO);
            List<Map<String, Object>> dto = getLightResultList(result);
            JsonElement tree = json.toJsonTree(dto);
            JsonObject jo = new JsonObject();
            jo.add("result", tree);
            resp.getWriter().write(jo.toString());
        }
        else if ("details".equalsIgnoreCase(req.getParameter("type")))
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.