Package javax.json

Examples of javax.json.JsonReader.readObject()


    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"));
View Full Code Here


    public void testEmptyObject() throws JSONException {
        JsonReader jsonReader = Json.createReader(Thread
                .currentThread()
                .getContextClassLoader()
                .getResourceAsStream("/1.json"));
        JsonObject json = jsonReader.readObject();
       
        assertNotNull(json);
        assertTrue(json.isEmpty());
    }
View Full Code Here

    public void testSimpleObjectWithTwoElements() throws JSONException {
        JsonReader jsonReader = Json.createReader(Thread
                .currentThread()
                .getContextClassLoader()
                .getResourceAsStream("/2.json"));
        JsonObject json = jsonReader.readObject();
       
        assertNotNull(json);
        assertFalse(json.isEmpty());
        assertTrue(json.containsKey("apple"));
        assertEquals("red", json.getString("apple"));
View Full Code Here

    public void testNestedStructure() throws JSONException {
        JsonReader jsonReader = Json.createReader(Thread
                .currentThread()
                .getContextClassLoader()
                .getResourceAsStream("/4.json"));
        JsonObject json = jsonReader.readObject();

        assertNotNull(json);
        assertFalse(json.isEmpty());
        assertTrue(json.containsKey("title"));
        assertEquals("The Matrix", json.getString("title"));
View Full Code Here

    }

    @Test
    public void testEmptyObject() throws JSONException {
        JsonReader jsonReader = Json.createReader(new StringReader("{}"));
        JsonObject json = jsonReader.readObject();
       
        assertNotNull(json);
        assertTrue(json.isEmpty());
    }
View Full Code Here

  }

  @Override
  public <T extends IResource> Bundle parseBundle(Class<T> theResourceType, Reader theReader) {
    JsonReader reader = Json.createReader(theReader);
    JsonObject object = reader.readObject();

    JsonValue resourceTypeObj = object.get("resourceType");
    assertObjectOfType(resourceTypeObj, JsonValue.ValueType.STRING, "resourceType");
    String resourceType = ((JsonString) resourceTypeObj).getString();
    if (!"Bundle".equals(resourceType)) {
View Full Code Here

  }

  @Override
  public <T extends IResource> T parseResource(Class<T> theResourceType, Reader theReader) {
    JsonReader reader = Json.createReader(theReader);
    JsonObject object = reader.readObject();

    JsonValue resourceTypeObj = object.get("resourceType");
    assertObjectOfType(resourceTypeObj, JsonValue.ValueType.STRING, "resourceType");
    String resourceType = ((JsonString) resourceTypeObj).getString();
View Full Code Here

  }

  @Override
  public TagList parseTagList(Reader theReader) {
    JsonReader reader = Json.createReader(theReader);
    JsonObject object = reader.readObject();

    JsonValue resourceTypeObj = object.get("resourceType");
    assertObjectOfType(resourceTypeObj, JsonValue.ValueType.STRING, "resourceType");
    String resourceType = ((JsonString) resourceTypeObj).getString();
View Full Code Here

    JsonReader reader;   
    JsonObject object;
   
    try {
      reader = Json.createReader(theReader);
      object = reader.readObject();
    } catch (JsonParsingException e) {
      if (e.getMessage().startsWith("Unexpected char 39")) {
        throw new DataFormatException("Failed to parse JSON encoded FHIR content: " + e.getMessage() + " - This may indicate that single quotes are being used as JSON escapes where double quotes are required", e);
      }
      throw new DataFormatException("Failed to parse JSON encoded FHIR content: " + e.getMessage(), e);
View Full Code Here

  }

  @Override
  public <T extends IResource> T parseResource(Class<T> theResourceType, Reader theReader) {
    JsonReader reader = Json.createReader(theReader);
    JsonObject object = reader.readObject();

    JsonValue resourceTypeObj = object.get("resourceType");
    assertObjectOfType(resourceTypeObj, JsonValue.ValueType.STRING, "resourceType");
    String resourceType = ((JsonString) resourceTypeObj).getString();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.