use of javax.json.JsonObject in project javaee7-samples by javaee-samples.
the class NameAddResourceTest method shouldFailAtLastNameNullValidation.
@Test
public void shouldFailAtLastNameNullValidation() throws Exception {
JsonObject name = startValidName().addNull("lastName").build();
Response response = postName(name);
assertFailedValidation(response);
}
use of javax.json.JsonObject in project jersey by jersey.
the class JsonProcessingTest method testJsonObject.
@Test
public void testJsonObject() throws Exception {
final Response response = target("jsonObject").request(MediaType.APPLICATION_JSON).post(Entity.json(JSON_OBJECT));
assertEquals(JSON_OBJECT, response.readEntity(JsonObject.class));
}
use of javax.json.JsonObject in project javaee7-samples by javaee-samples.
the class DOMGeneratorTest method testNestedStructure.
@Test
public void testNestedStructure() throws JSONException {
JsonObject jsonObject = Json.createObjectBuilder().add("title", "The Matrix").add("year", 1999).add("cast", Json.createArrayBuilder().add("Keanu Reaves").add("Laurence Fishburne").add("Carrie-Anne Moss")).build();
StringWriter w = new StringWriter();
try (JsonWriter writer = Json.createWriter(w)) {
writer.write(jsonObject);
}
JSONAssert.assertEquals("{\"title\":\"The Matrix\",\"year\":1999,\"cast\":[\"Keanu Reaves\",\"Laurence Fishburne\",\"Carrie-Anne Moss\"]}", w.toString(), JSONCompareMode.STRICT);
}
use of javax.json.JsonObject in project javaee7-samples by javaee-samples.
the class JsonReaderFromReaderTest method testEmptyObject.
@Test
public void testEmptyObject() throws JSONException {
JsonReader jsonReader = Json.createReader(new StringReader("{}"));
JsonObject json = jsonReader.readObject();
assertNotNull(json);
assertTrue(json.isEmpty());
}
use of javax.json.JsonObject in project javaee7-samples by javaee-samples.
the class JsonReaderFromReaderTest method testSimpleObjectWithTwoElements.
@Test
public void testSimpleObjectWithTwoElements() throws JSONException {
JsonReader jsonReader = Json.createReader(new StringReader("{" + " \"apple\":\"red\"," + " \"banana\":\"yellow\"" + "}"));
JsonObject json = jsonReader.readObject();
assertNotNull(json);
assertFalse(json.isEmpty());
assertTrue(json.containsKey("apple"));
assertEquals("red", json.getString("apple"));
assertTrue(json.containsKey("banana"));
assertEquals("yellow", json.getString("banana"));
}
Aggregations