Package javax.json

Examples of javax.json.JsonObject


    }

    @Override
    @NotNull(message = "JSON is never NULL")
    public JsonObject json() throws IOException {
        final JsonObject obj = new JsonNode(
            this.storage.xml().nodes(this.xpath()).get(0)
        ).json();
        final JsonObjectBuilder json = Json.createObjectBuilder();
        for (final Map.Entry<String, JsonValue> val : obj.entrySet()) {
            json.add(val.getKey(), val.getValue());
        }
        return json
            .add(
                "comments",
View Full Code Here


            .add("sha").set(sha).up()
            .add("url").set("http://localhost/4").up()
            .add("html_url").set("http://localhost/5").up()
            .add("message").set(json.getString("message")).up();
        if (json.containsKey("committer")) {
            final JsonObject committer = json.getJsonObject("committer");
            commit.add("committer")
                .add("email").set(committer.getString("email")).up()
                .add("name").set(committer.getString("name")).up();
        }
        if (json.containsKey("author")) {
            final JsonObject author = json.getJsonObject("author");
            commit.add("author")
                .add("email").set(author.getString("email")).up()
                .add("name").set(author.getString("name")).up();
        }
        this.storage.apply(commit);
        return new MkRepoCommit(this.storage, this.repo(), sha);
    }
View Full Code Here

     * MkCommits can create commits.
     * @throws Exception If something goes wrong.
     */
    @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(
View Full Code Here

     * Return a Tree for testing.
     * @return Tree
     * @throws Exception If something goes wrong.
     */
    private Tree tree() throws Exception {
        final JsonObject json = Json.createObjectBuilder().add(
            "tree",
            Json.createArrayBuilder().add(
                Json.createObjectBuilder()
                    .add("sha", "abcsha12").add("message", "test tree")
                    .add("name", "v.0.1").build()
View Full Code Here

        @NotNull(message = "file name can't be NULL") final String file,
        @NotNull(message = "file content can't be NULL") final String content)
        throws IOException {
        final JsonObjectBuilder builder = Json.createObjectBuilder()
            .add("content", content);
        final JsonObject json = Json.createObjectBuilder()
            .add("files", Json.createObjectBuilder().add(file, builder))
            .build();
        this.patch(json);
    }
View Full Code Here

         * @return User name
         * @throws IOException If it fails
         */
        @NotNull(message = "Name is never NULL")
        public String name() throws IOException {
            final JsonObject json = this.json();
            if (!json.containsKey("name")) {
                throw new IllegalStateException(
                    String.format(
                        // @checkstyle LineLength (1 line)
                        "User %s doesn't have a name specified in his/her Github account; use #hasName() first.",
                        this.login()
                    )
                );
            }
            return json.getString("name");
        }
View Full Code Here

    }

    @Override
    @NotNull(message = "JSON is never NULL")
    public JsonObject json() throws IOException {
        final JsonObject json = new RtJson(this.entry)
            .fetch()
            .getJsonObject("resources");
        if (!json.containsKey(this.res)) {
            throw new IllegalStateException(
                String.format(
                    "'%s' is absent in JSON: %s", this.res, json
                )
            );
        }
        return json.getJsonObject(this.res);
    }
View Full Code Here

    @NotNull(message = "T is never NULL")
    public <T> T value(
        @NotNull(message = "name can't be NULL") final String name,
        @NotNull(message = "type can't be NULL") final Class<T> type
    ) throws IOException {
        final JsonObject json = this.json();
        if (!json.containsKey(name)) {
            throw new IllegalStateException(
                String.format(
                    "'%s' is absent in JSON: %s", name, json
                )
            );
        }
        final JsonValue value = json.get(name);
        if (value == null) {
            throw new IllegalStateException(
                String.format(
                    "'%s' is NULL in %s", name, json
                )
View Full Code Here

    @Test
    public void canRetrieveAsJson() throws Exception {
        final String head = "blah";
        final String base = "aaa";
        final Pull pull = repo().pulls().create("Test Pull Json", head, base);
        final JsonObject json = pull.json();
        MatcherAssert.assertThat(
            json.getString("number"),
            Matchers.equalTo("1")
        );
        MatcherAssert.assertThat(
            json.getString("head"),
            Matchers.equalTo(head)
        );
        MatcherAssert.assertThat(
            json.getString("base"),
            Matchers.equalTo(base)
        );
    }
View Full Code Here

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

TOP

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