Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONObject


     * Test a basic JSON Object construction
     */
    public void test_compact() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject("{\"foo\":\"bar\", \"bool\": true}");
            assertTrue(jObject.getBoolean("bool") == true);
            System.out.println("JSON compacted text (jObject):\n");
            System.out.println(jObject.toString());
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here


    public void test_parseFailure() {
        Exception ex = null;

        try {
            // Verify a malformed JSON string (no closure), fails parse.
            JSONObject jObject = new JSONObject("{\"foo\":\"bar\", \"bool\": true");
            assertTrue(jObject.getBoolean("bool") == true);
            System.out.println("JSON compacted text (jObject):\n");
            System.out.println(jObject.toString());
        } catch (Exception ex1) {
            ex = ex1;
        }
        assertTrue(ex instanceof JSONException);
    }
View Full Code Here

    public void test_noQuotesParseFailure() {
        Exception ex = null;

        try {
            // Verify a malformed JSON string (no quotes on attributes), fails parse in strict mode.
            JSONObject jObject = new JSONObject("{foo:\"bar\", bool: true}", true);
            assertTrue(jObject.getBoolean("bool") == true);
            System.out.println("JSON compacted text (jObject):\n");
            System.out.println(jObject.toString());
        } catch (Exception ex1) {
            ex = ex1;
        }
        assertTrue(ex instanceof JSONException);
    }
View Full Code Here

     */
    public void test_verbose() {
        Exception ex = null;

        try {
            JSONObject jObject = new JSONObject("{\"foo\":\"bar\", \"bool\": true}");
            assertTrue(jObject.getBoolean("bool") == true);
            System.out.println("JSON indented tab space (jObject):\n");
            System.out.println(jObject.toString(true));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     */
    public void test_verbose_depth() {
        Exception ex = null;

        try {
            JSONObject jObject = new JSONObject("{\"foo\":\"bar\", \"bool\": true}");
            assertTrue(jObject.getBoolean("bool") == true);
            System.out.println("JSON indented 3 space (jObject):\n");
            System.out.println(jObject.toString(3));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     */
    public void test_has() {
        Exception ex = null;

        try {
            JSONObject jObject = new JSONObject("{\"foo\":\"bar\", \"bool\": false, \"null\": null}");
            assertTrue(jObject.has("foo"));
            assertTrue(jObject.has("bool"));
            assertTrue(jObject.has("null"));
            assertTrue(!jObject.has("noKey"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

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

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

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

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

TOP

Related Classes of org.apache.wink.json4j.JSONObject

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.