Package javax.json

Examples of javax.json.JsonArray


        return registrations.find(registrationId);
    }

    @GET
    public Response all() {
        JsonArray registrationList = this.registrations.allAsJson();
        if (registrationList == null || registrationList.isEmpty()) {
            return Response.noContent().build();
        }
        return Response.ok(registrationList).build();
    }
View Full Code Here


    }

    @Test
    public void convertEmptyListToJson() {
        mockQuery(Registration.findAll, Collections.EMPTY_LIST);
        final JsonArray result = this.cut.allAsJson();
        assertNotNull(result);
        assertTrue(result.isEmpty());
    }
View Full Code Here

        List<Registration> registrations = new ArrayList<>();
        Registration expected = mock(Registration.class);
        when(expected.getId()).thenReturn(42l);
        registrations.add(expected);
        mockQuery(Registration.findAll, registrations);
        final JsonArray result = this.cut.allAsJson();
        assertNotNull(result);
        assertThat(result.size(), is(1));
        JsonObject actual = result.getJsonObject(0);
        JsonNumber actualId = actual.getJsonNumber(Registrations.CONFIRMATION_ID);
        assertThat(expected.getId(), is(actualId.longValue()));

    }
View Full Code Here

    public void testFilterDocuments() throws Exception {
        // Store documents.
        target("document/multiple").request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(getDocumentJsonArray()));

        // Filter.
        JsonArray filter = Json.createArrayBuilder().add("site").build();
        JsonArray filtered = target("document/filter").request(MediaType.APPLICATION_JSON)
                .post(Entity.json(filter), JsonArray.class);

        checkFilteredDocuments(filtered, 2, "site");

        filter = Json.createArrayBuilder().add("site").add("age").build();
View Full Code Here

        expected.setMessage("patchedMessage");
        expected.setTitle("patchedTitle");
        expected.getList().add("one");
        expected.getList().add("two");

        JsonArray patch_1 = Json.createArrayBuilder()
                .add(Json.createObjectBuilder()
                        .add("op", "replace")
                        .add("path", "/message")
                        .add("value", expected.getMessage())
                        .build())
                .add(Json.createObjectBuilder()
                        .add("op", "replace")
                        .add("path", "/title")
                        .add("value", expected.getTitle())
                        .build())
                .add(Json.createObjectBuilder()
                        .add("op", "replace")
                        .add("path", "/list")
                        .add("value", Json.createArrayBuilder()
                                .add(expected.getList().get(0))
                                .add(expected.getList().get(1))
                                .build())
                        .build())
                .build();

        assertEquals(expected, target.request("application/json")
                .method("PATCH", Entity.entity(patch_1, PatchingInterceptor.PATCH_MEDIA_TYPE), State.class));
        assertEquals(expected, target.request("application/json").get(State.class));

        // apply second patch
        expected.getList().add("three");

        JsonArray patch_2 = Json.createArrayBuilder()
                .add(Json.createObjectBuilder()
                        .add("op", "add")
                        .add("path", "/list/-")
                        .add("value", expected.getList().get(2))
                        .build())
View Full Code Here

            equalTo("{\"firstName\":\"Tom\",\"lastName\":\"Tommyknocker\"}"));
    }

    @Test
    public void testWriteJsonArray() throws Exception {
        final JsonArray obj = Json.createArrayBuilder()            
            .add(
                Json.createObjectBuilder()
                    .add("firstName", "Tom")
                    .add("lastName", "Tommyknocker")
            )
View Full Code Here

        JsonObject obj = r.readEntity(JsonObject.class);
        assertThat(obj.getInt("id"), equalTo(1));
        assertThat(obj.getString("name"), equalTo("Book 1"));
        assertThat(obj.get("chapters"), instanceOf(JsonArray.class));
       
        final JsonArray chapters = (JsonArray)obj.get("chapters");
        assertThat(chapters.size(), equalTo(2));
        assertThat(((JsonObject)chapters.get(0)).getInt("id"), equalTo(1));
        assertThat(((JsonObject)chapters.get(0)).getString("title"), equalTo("Chapter 1"));
        assertThat(((JsonObject)chapters.get(1)).getInt("id"), equalTo(2));
        assertThat(((JsonObject)chapters.get(1)).getString("title"), equalTo("Chapter 2"));
    }
View Full Code Here

        testPostSimpleJsonObject();
       
        final Response r = createWebClient("/bookstore/books").get();
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
       
        final JsonArray obj = r.readEntity(JsonArray.class);
        assertThat(obj.size(), equalTo(1));
        assertThat(obj.get(0), instanceOf(JsonObject.class));
       
        assertThat(((JsonObject)obj.get(0)).getInt("id"), equalTo(1));
        assertThat(((JsonObject)obj.get(0)).getString("name"), equalTo("Book 1"));
    }
View Full Code Here

        return builder.build();
    }
   
    private Book bookFromJson(JsonObject obj) {
        final Book book = new Book(obj.getString("name"), obj.getInt("id"));
        final JsonArray chapters = (JsonArray)obj.get("chapters");
        if (chapters != null && !chapters.isEmpty()) {
            for (final JsonObject chapter: chapters.getValuesAs(JsonObject.class)) {
                book.addChapter(chapter.getInt("id"), chapter.getString("title"));
            }
        }
       
        return book;
View Full Code Here

    public Set<String> getJdbcConnectionPools() {
        return getChildResources("resources/jdbc-connection-pool");
    }

    public Map<String, String> getJdbcConnectionPoolParameters(String poolName) {
        JsonArray properties = getExtraProperties("resources/jdbc-connection-pool/" + urlEncode(poolName) + "/property");
        if (properties == null) {
            return null;
        }
        Map<String, String> result = new HashMap<>();
        for (JsonValue value : properties) {
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.