use of javax.json.JsonArray in project jersey by jersey.
the class JsonProcessingTest method testJsonArrayAsString.
@Test
public void testJsonArrayAsString() throws Exception {
final Response response = target("jsonArray").request(MediaType.APPLICATION_JSON).post(Entity.json(JSON_ARRAY_STR));
assertEquals(JSON_ARRAY, response.readEntity(JsonArray.class));
}
use of javax.json.JsonArray in project jersey by jersey.
the class JsonProcessingTest method testJsonArrayValueEntity.
@Test
public void testJsonArrayValueEntity() throws Exception {
final Response response = target("jsonArray").request(MediaType.APPLICATION_JSON).post(Entity.json(JSON_ARRAY_VALUE));
assertEquals(JSON_ARRAY_VALUE, response.readEntity(JsonArray.class));
}
use of javax.json.JsonArray in project jersey by jersey.
the class JsonProcessingResourceTest method testFilterDocuments.
@Test
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();
filtered = target("document/filter").request(MediaType.APPLICATION_JSON).post(Entity.json(filter), JsonArray.class);
checkFilteredDocuments(filtered, 3, "site", "age");
// Remove All.
target("document").request().delete();
}
use of javax.json.JsonArray in project javaee7-samples by javaee-samples.
the class JsonReaderFromReaderTest method testArray.
@Test
public void testArray() throws JSONException {
JsonReader jsonReader = Json.createReader(new StringReader("[" + " { \"apple\":\"red\" }," + " { \"banana\":\"yellow\" }" + "]"));
JsonArray jsonArr = jsonReader.readArray();
assertNotNull(jsonArr);
assertEquals(2, jsonArr.size());
JSONAssert.assertEquals("{\"apple\":\"red\"}", jsonArr.get(0).toString(), JSONCompareMode.STRICT);
JSONAssert.assertEquals("{\"banana\":\"yellow\"}", jsonArr.get(1).toString(), JSONCompareMode.STRICT);
}
use of javax.json.JsonArray in project javaee7-samples by javaee-samples.
the class JsonReaderFromStreamTest method testArray.
@Test
public void testArray() throws JSONException {
JsonReader jsonReader = Json.createReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("/3.json"));
JsonArray jsonArr = jsonReader.readArray();
assertNotNull(jsonArr);
assertEquals(2, jsonArr.size());
JSONAssert.assertEquals("{\"apple\":\"red\"}", jsonArr.get(0).toString(), JSONCompareMode.STRICT);
JSONAssert.assertEquals("{\"banana\":\"yellow\"}", jsonArr.get(1).toString(), JSONCompareMode.STRICT);
}
Aggregations