Package javax.json

Examples of javax.json.JsonReader


            return;
        }

        try {
            InputStream inputStream = null;
            JsonReader jsonReader = null;
            if (null != input.getByteStream()) {
                inputStream = input.getByteStream();
                jsonReader = Json.createReader(new InputStreamReader(inputStream));
            } else if (null != input.getCharacterStream()) {
                jsonReader = Json.createReader(input.getCharacterStream());
            } else {
                try {
                    URL url = new URL(input.getSystemId());
                    inputStream = url.openStream();
                } catch (MalformedURLException malformedURLException) {
                    try {
                        inputStream = new FileInputStream(input.getSystemId());
                    } catch (FileNotFoundException fileNotFoundException) {
                        throw malformedURLException;
                    }
                }
                jsonReader = Json.createReader(new InputStreamReader(inputStream));
            }
            if (jsonReader != null) {
                JsonStructure structure = jsonReader.read();
                parseRoot(structure);
            }

            if (null != inputStream) {
                inputStream.close();
View Full Code Here


   }

   @Override
   public JsonArray readFrom(Class<JsonArray> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException
   {
      JsonReader reader = findReader(mediaType, entityStream);
      try
      {
         return reader.readArray();
      }
      finally
      {
         reader.close();
      }
   }
View Full Code Here

   }

   @Override
   public JsonStructure readFrom(Class<JsonStructure> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException
   {
      JsonReader reader = findReader(mediaType, entityStream);
      try
      {
         return reader.read();
      }
      finally
      {
         reader.close();
      }
   }
View Full Code Here

        assertTrue(json.isEmpty());
    }

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

        assertEquals("yellow", json.getString("banana"));
    }

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

                .addAsLibraries(requiredLibraries);
    }

    @Test
    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

        assertTrue(json.isEmpty());
    }

    @Test
    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

        assertEquals("yellow", json.getString("banana"));
    }

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

        JSONAssert.assertEquals("{\"banana\":\"yellow\"}", jsonArr.get(1).toString(), JSONCompareMode.STRICT);
    }

    @Test
    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

                .addAsLibraries(requiredLibraries);
    }

    @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

TOP

Related Classes of javax.json.JsonReader

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.