Package com.google.gson

Examples of com.google.gson.JsonObject


  private FuzzingContext context;

  @Override
  public void setUp() {
    Random random = new Random(123);
    JsonObject config = TestConfig.getConfig();
    context = new FuzzingContext(random, config, true);
  }
View Full Code Here


    int budget = 10;
    Node node = fuzzer.generate(budget);
    String code = ArrayFuzzer.getPrettyCode(node);
    assertTrue(code.startsWith("["));
    assertTrue(code.endsWith("]"));
    JsonObject config = fuzzer.getOwnConfig();
    assertTrue(
        "\nGenerated code: \n" + code,
        code.split(",").length
            < (int) (config.get("maxLength").getAsDouble()
                * (budget - 1)));
  }
View Full Code Here

    assertEquals(code1, code2);
  }
  private static void leaveOneSubtype(JsonObject typeConfig, String subtypeName)
      throws JsonParseException {
    JsonObject weightConfig = typeConfig.get("weights").getAsJsonObject();

    for (Entry<String, JsonElement> entry : weightConfig.entrySet()) {
      String name = entry.getKey();
      if (name.equals(subtypeName)) {
        weightConfig.addProperty(name, 1);
      } else {
        weightConfig.addProperty(name, 0);
      }
    }
  }
View Full Code Here

          br.close();
        }

        // Parse the credentials
        JsonParser parser = new JsonParser();
        JsonObject obj = (JsonObject) parser.parse(json.toString());

        // Create a client
        JumblrClient client = new JumblrClient(
            obj.getAsJsonPrimitive("consumer_key").getAsString(),
            obj.getAsJsonPrimitive("consumer_secret").getAsString()
        );

        // Give it a token
        client.setToken(
            obj.getAsJsonPrimitive("oauth_token").getAsString(),
            obj.getAsJsonPrimitive("oauth_token_secret").getAsString()
        );

        // Usage
        List<Post> posts = client.blogPosts("seejohnrun");
        for (Post post : posts) {
View Full Code Here

    public Post getPost() {
        return get("post", Post.class);
    }

    public Long getId() {
        JsonObject object = (JsonObject) response;
        return object.get("id").getAsLong();
    }
View Full Code Here

    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Post> getPosts() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<Post> l = gson.fromJson(object.get("posts"), new TypeToken<List<Post>>() {}.getType());
        for (Post e : l) { e.setClient(client); }
        return l;
    }
View Full Code Here

    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<User> getUsers() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<User> l = gson.fromJson(object.get("users"), new TypeToken<List<User>>() {}.getType());
        for (User e : l) { e.setClient(client); }
        return l;
    }
View Full Code Here

    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Post> getLikedPosts() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<Post> l = gson.fromJson(object.get("liked_posts"), new TypeToken<List<Post>>() {}.getType());
        for (Post e : l) { e.setClient(client); }
        return l;
    }
View Full Code Here

    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Blog> getBlogs() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<Blog> l = gson.fromJson(object.get("blogs"), new TypeToken<List<Blog>>() {}.getType());
        for (Blog e : l) { e.setClient(client); }
        return l;
    }
View Full Code Here

     **
     **/

    private <T extends Resource> T get(String field, Class<T> k) {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        T e = gson.fromJson(object.get(field).toString(), k);
        e.setClient(client);
        return e;
    }
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.