Package javax.json

Examples of javax.json.JsonArray


    @Test
    public final void createsMkCommit() throws Exception {
        final JsonObject author = Json.createObjectBuilder()
            .add("name", "Scott").add("email", "Scott@gmail.com")
            .add("date", "2008-07-09T16:13:30+12:00").build();
        final JsonArray tree = Json.createArrayBuilder()
            .add("xyzsha12").build();
        final Commit newCommit = this.repo().git().commits().create(
            Json.createObjectBuilder().add("message", "my commit message")
                .add("sha", "12ahscba")
                .add("tree", "abcsha12")
View Full Code Here


    @NotNull(message = "created tree is never NULL")
    @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
    public Tree create(
        @NotNull(message = "params can't be NULL") final JsonObject params
    ) throws IOException {
        final JsonArray trees = params.getJsonArray("tree");
        for (final JsonValue val : trees) {
            final JsonObject tree = (JsonObject) val;
            final String sha = tree.getString("sha");
            final Directives dirs = new Directives().xpath(this.xpath())
                .add("tree");
            for (final Entry<String, JsonValue> entry : tree.entrySet()) {
                dirs.add(entry.getKey()).set(entry.getValue().toString()).up();
            }
            this.storage.apply(dirs);
            final String ref;
            if (tree.containsValue("name")) {
                ref = tree.getString("name");
            } else {
                ref = sha;
            }
            new MkReferences(this.storage, this.self, this.coords).create(
                new StringBuilder("refs/trees/").append(ref).toString(),
                sha
            );
        }
        return this.get(trees.getJsonObject(0).getString("sha"));
    }
View Full Code Here

         * @return Commits
         * @throws IOException If there is any I/O problem
         */
        @NotNull(message = "Iterable of commits is never NULL")
        public Iterable<RepoCommit> commits() throws IOException {
            final JsonArray array = this.comparison.json()
                .getJsonArray("commits");
            final Collection<RepoCommit> commits =
                new ArrayList<RepoCommit>(array.size());
            final RepoCommits repo = this.comparison.repo().commits();
            for (final JsonValue value : array) {
                commits.add(
                    repo.get(JsonObject.class.cast(value).getString("sha"))
                );
View Full Code Here

            if (link == null) {
                this.more = false;
            } else {
                this.request = response.jump(link.uri());
            }
            final JsonArray arr = response.as(JsonResponse.class).json()
                .readArray();
            final Queue<P> list = new LinkedList<P>();
            for (final JsonValue value : arr) {
                list.add((P) value);
            }
View Full Code Here

     * RtContents can iterate through a directory's contents.
     * @throws Exception If something goes wrong.
     */
    @Test
    public void canIterateDirectoryContents() throws Exception {
        final JsonArray body = Json.createArrayBuilder().add(
            Json.createObjectBuilder()
                .add("path", "README.md")
                .build()
        ).add(
            Json.createObjectBuilder()
                .add("path", ".gitignore")
                .build()
        ).build();
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())
        ).next(new MkAnswer.Simple("{\"path\":\"README.md\"}"))
            .next(new MkAnswer.Simple("{\"path\":\".gitignore\"}"))
            .start();
        final RtContents contents = new RtContents(
            new ApacheRequest(container.home()),
View Full Code Here

      String filename = outputdir + "/patterns" + ".json";

      JsonArrayBuilder obj = Json.createArrayBuilder();
      if (writtenPatInJustification.containsKey(label) && writtenPatInJustification.get(label)) {
        JsonReader jsonReader = Json.createReader(new BufferedInputStream(new FileInputStream(filename)));
        JsonArray objarr = jsonReader.readArray();
        jsonReader.close();
        for (JsonValue o : objarr)
          obj.add(o);
      } else
        obj = Json.createArrayBuilder();
View Full Code Here

        JsonArrayBuilder obj = Json.createArrayBuilder();
        if (writtenInJustification.containsKey(label)
            && writtenInJustification.get(label)) {
          JsonReader jsonReader = Json.createReader(new BufferedInputStream(
              new FileInputStream(filename)));
          JsonArray objarr = jsonReader.readArray();
          for (JsonValue o : objarr)
            obj.add(o);
          jsonReader.close();

        }
View Full Code Here

   */
  @Test
  public void testCase01() throws Exception {
    System.out.println("*** testCase01");
    try (JsonReader reader = Json.createReader(new FileReader("src/test/resources/case01.txt"))) {
      JsonArray arr = reader.readArray();
      System.out.println("Version 1 of items iteration");
      for (int i = 0; i < arr.size(); i++) {
        System.out.printf("Value[%s]=%s\n", i, arr.getString(i));
      }
      System.out.println("Version 2 of items iteration");
      for (JsonValue v : arr) {
        System.out.printf("Value=%s\n", v.toString());
      }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testCase03() throws Exception {
    System.out.println("*** testCase03");
    JsonArray arrLibraries = Json.createArrayBuilder().add("Lux City").add("Lux Concorde").build();
    JsonObject obj = Json.createObjectBuilder().add("bookName", "Lord of the Rings").add("priceInEuro", 25).add("libraries", arrLibraries).build();
    File f = new File("target/case03.txt");
    try (JsonWriter jsonWriter = Json.createWriter(new FileOutputStream(f, false))) {
      jsonWriter.writeObject(obj);
      System.out.printf("File saved to %s.\n", f.getAbsolutePath());
View Full Code Here

      for (String name : object.keySet())
        navigateTree(object.get(name), name);
      break;
    case ARRAY:
      System.out.println("ARRAY");
      JsonArray array = (JsonArray) tree;
      for (JsonValue val : array)
        navigateTree(val, null);
      break;
    case STRING:
      JsonString st = (JsonString) tree;
View Full Code Here

TOP

Related Classes of javax.json.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.