Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONArray


    public void test_newFromStringArray() {
        Exception ex = null;
        try {
            String[] strArray = new String[] {"hello", "world", null, "after null"};

            JSONArray jArray = new JSONArray(strArray);
            assertTrue(jArray.length() == 4);
            assertTrue(jArray.getString(0).equals("hello"));
            assertTrue(jArray.optString(2) == null);
            assertTrue(jArray.getString(3).equals("after null"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here


    /**
     * Test the String empty object contructor.
     */
    public void test_newFromEmptyObjectString() {
        JSONArray jObject = null;
        Exception ex = null;
        // Load from empty object string.
        try {
            jObject = new JSONArray("[]");
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 0);
    }
View Full Code Here

    /**
     * Test the String non-empty object contructor.
     */
    public void test_newFromString() {
        JSONArray jObject = null;
        Exception ex = null;
        // Load a basic JSON string
        try {
            jObject = new JSONArray("[\"foo\", \"bar\", \"bool\", true]");
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 4);
    }
View Full Code Here

    /**
     * Test the construction from a reader.
     */
    public void test_newFromReader() {
        JSONArray jObject = null;
        Exception ex = null;
        // read in a basic JSON file of a toplevel array that has all the various types in it.
        try {
            Reader rdr = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("utf8_basic_array.json"), "UTF-8");
            jObject = new JSONArray(rdr);
            rdr.close();
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 7);
        assertTrue(ex == null);
    }
View Full Code Here

    /**
     * Test the construction from a stream.
     */
    public void test_newFromStream() {
        JSONArray jObject = null;
        Exception ex = null;
        // read in a basic JSON file of a toplevel array that has all the various types in it.
        // Inputstreams are read as UTF-8 by the underlying parser.
        try {
            InputStream is = this.getClass().getClassLoader().getResourceAsStream("utf8_basic_array.json");
            jObject = new JSONArray(is);
            is.close();
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 7);
        assertTrue(ex == null);
    }
View Full Code Here

    /**
     * Test the String non-empty object contructor parse failure.
     */
    public void test_newFromStringFailure() {
        JSONArray jObject = null;
        Exception ex = null;

        // Load a basic JSON string that's not valid in strict (unquoted string)
        try {
            jObject = new JSONArray("[\"foo\", bar, \"bool\", true]", true);
        } catch (Exception ex1) {
            ex = ex1;
        }
        assertTrue(ex != null);
        assertTrue(ex instanceof JSONException);
View Full Code Here

     * Test a basic JSON Array construction and helper 'put' function
     */
    public void test_putLong() {
        Exception ex = null;
        try {
            JSONArray jArray = new JSONArray();
            jArray.put((long)1);
            Long l = (Long)jArray.get(0);
            assertTrue(l != null);
            assertTrue(l instanceof java.lang.Long);
            assertTrue(jArray.getLong(0) == 1);
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     * Test a basic JSON Array construction and helper 'put' function
     */
    public void test_putInt() {
        Exception ex = null;
        try {
            JSONArray jArray = new JSONArray();
            jArray.put(1);
            Integer i = (Integer)jArray.get(0);
            assertTrue(i != null);
            assertTrue(i instanceof java.lang.Integer);
            assertTrue(jArray.getInt(0) == 1);
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     * Test a basic JSON Array construction and helper 'put' function
     */
    public void test_putShort() {
        Exception ex = null;
        try {
            JSONArray jArray = new JSONArray();
            jArray.put((short)1);
            Short s = (Short)jArray.get(0);
            assertTrue(s != null);
            assertTrue(s instanceof java.lang.Short);
            assertTrue(jArray.getShort(0) == 1);
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     * Test a basic JSON Array construction and helper 'put' function
     */
    public void test_putDouble() {
        Exception ex = null;
        try {
            JSONArray jArray = new JSONArray();
            jArray.put((double)1.123);
            Double d = (Double)jArray.get(0);
            assertTrue(d != null);
            assertTrue(d instanceof java.lang.Double);
            assertTrue(jArray.getDouble(0) == 1.123);
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.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.