Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONObject


        @GET
        @Path("json")
        @Produces("application/json")
        public JSONObject getJson() throws Exception {
            return new JSONObject(JSON);
        }
View Full Code Here


    /**
     * Test the noargs contructor.
     */
    public void test_new() {
        JSONObject jObject = new JSONObject();
        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 {
            jObject = new JSONObject("{}");
        } 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 {
            jObject = new JSONObject("{\"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");
            jObject = new JSONObject(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 stream.
     */
    public void test_newFromStream() {
        JSONObject jObject = null;
        Exception ex = null;
        // read in a basic JSON file 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.json");
            jObject = new JSONObject(is);
            is.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;
        JSONArray jArr = 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));
        map.put("strArr", new String[]{"first", "second", "third"});

        // Load a JSON object from a map with JSONable values.
        try {
            jObject = new JSONObject(map);
            jArr = (JSONArray)jObject.get("strArr");
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(jObject != null);
        assertTrue(jObject.length() == 5);
        assertTrue("first".equals((String)jArr.get(0)));
        assertTrue("second".equals((String)jArr.get(1)));
        assertTrue("third".equals((String)jArr.get(2)));

        assertTrue(ex == null);
View Full Code Here

     */
    public void test_newFromBean() {
        Exception ex = null;
        try {
            Date date = new Date();
            JSONObject ja = new JSONObject(date);
            assertTrue(ja.get("class").equals("java.util.Date"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     */
    public void test_newFromBeanWithSuper() {
        Exception ex = null;
        try {
            Date date = new Date();
            JSONObject ja = new JSONObject(date, true);
            assertTrue(ja.get("class").equals("java.util.Date"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     */
    public void test_newFromBeanWithOutSuper() {
        Exception ex = null;
        try {
            Date date = new Date();
            JSONObject ja = new JSONObject(date, false);
            assertTrue(ja.opt("class") == null);
        } 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.