Package org.apache.wink.json4j.compat

Examples of org.apache.wink.json4j.compat.JSONObject


        try {
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            JSONArray jArray = factory.createJSONArray();
            jArray.put(factory.createJSONObject());
            JSONObject obj = (JSONObject)jArray.get(0);
            assertTrue(obj != null);
            assertTrue(obj instanceof JSONObject);
            assertTrue(((JSONObject)jArray.get(0)).toString().equals("{}"));
        } catch (Exception ex1) {
            ex = ex1;
View Full Code Here


            JSONStringer jStringer = factory.createJSONStringer();
            jStringer.object();
            jStringer.endObject();
            String str = jStringer.toString();
            // Verify it parses.
            JSONObject test = factory.createJSONObject(str);
            assertTrue(str.equals("{}"));
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

            jStringer.object();
            jStringer.close();
            String str = jStringer.toString();
            System.out.println("STRING: " + str);
            // Verify it parses.
            JSONObject test = factory.createJSONObject(str);
            assertTrue(str.equals("{}"));
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

            jStringer.endObject();

            String str = jStringer.toString();

            // Verify it parses.
            JSONObject test = factory.createJSONObject(str);
            assertTrue(str.equals("{\"string\":\"String1\",\"bool\":false,\"number\":1,\"object\":{\"string\":\"String2\"},\"array\":[1,2.0,3]}"));
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

     * Test the noargs contructor.
     */
    public void test_new() {
        System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
        JSONFactory factory = JSONFactory.newInstance();
        JSONObject jObject = factory.createJSONObject();
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 0);
    }
View Full Code Here

    /**
     * Test the String empty object contructor.
     */
    public void test_newFromEmptyObjectString() {
        JSONObject jObject = null;
        Exception ex = null;
        // Load from empty object string.
        try{
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            jObject = factory.createJSONObject("{}");
        }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() {
        JSONObject jObject = null;
        Exception ex = null;
        // Load a basic JSON string
        try{
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            jObject = factory.createJSONObject("{\"foo\":\"bar\", \"bool\": true}");
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 2);
    }
View Full Code Here

    /**
     * Test the construction from a reader.
     */
    public void test_newFromReader() {
        JSONObject jObject = null;
        Exception ex = null;
        // read in a basic JSON file that has all the various types in it.
        try{
            Reader rdr = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("utf8_basic.json"), "UTF-8");
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            jObject = factory.createJSONObject(rdr);
            rdr.close();
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 12);
        assertTrue(ex == null);
    }
View Full Code Here

    /**
     * Test the construction from a simple map.
     */
    public void test_newFromMap() {
        JSONObject jObject = null;
        Exception ex = null;
        HashMap map = new HashMap();
        map.put("string", "This is a string");
        map.put("null", null);
        map.put("integer", new Integer(1));
        map.put("bool", new Boolean(true));

        // Load a JSON object from a map with JSONable values.
        try{
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            jObject = factory.createJSONObject(map);
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 4);
        assertTrue(ex == null);
    }
View Full Code Here

    public void test_compact() {
        Exception ex = null;
        try {
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            JSONObject jObject = factory.createJSONObject("{\"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

TOP

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