Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONObject


     * Test a basic JSON Object construction and helper 'put' function
     */
    public void test_putBoolean() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            jObject.put("bool", true);
            Boolean b = (Boolean)jObject.get("bool");
            assertTrue(b != null);
            assertTrue(b instanceof java.lang.Boolean);
            assertTrue(jObject.getBoolean("bool") == true);
        } 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_putString() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            jObject.put("string", "Hello World.");
            String s = (String)jObject.get("string");
            assertTrue(s != null);
            assertTrue(s instanceof java.lang.String);
            assertTrue(jObject.getString("string").equals("Hello World."));
        } 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_putJSONObject() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            jObject.put("object", new JSONObject());
            JSONObject obj = (JSONObject)jObject.get("object");
            assertTrue(obj != null);
            assertTrue(obj instanceof JSONObject);
            assertTrue(((JSONObject)jObject.get("object")).toString().equals("{}"));
        } catch (Exception ex1) {
            ex = ex1;
View Full Code Here

     * Test a basic JSON Object construction and helper 'put' function
     */
    public void test_putJSONArray() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            jObject.put("array", new JSONArray());
            JSONArray obj = (JSONArray)jObject.get("array");
            assertTrue(obj != null);
            assertTrue(obj instanceof JSONArray);
            assertTrue(((JSONArray)jObject.get("array")).toString().equals("[]"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     * Test append function to convert an existing value to an array.
     */
    public void test_append() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            jObject.put("string", "Hello World.");
            String s = (String)jObject.get("string");
            assertTrue(s != null);
            assertTrue(s instanceof java.lang.String);
            jObject.append("string", "Another string.");
            JSONArray array = (JSONArray)jObject.get("string");
            assertTrue(array != null);
            assertTrue(array instanceof JSONArray);
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
View Full Code Here

     * Test append function to convert an existing value (though null) to an array.
     */
    public void test_appendtoNull() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            jObject.put("null", (Object)null);
            String s = (String)jObject.get("null");
            assertTrue(s == null);
            assertTrue(jObject.has("null"));
            jObject.append("null", "Another string.");
            JSONArray array = (JSONArray)jObject.get("null");
            assertTrue(array != null);
            assertTrue(array instanceof JSONArray);
            assertTrue(array.size() == 2);
            assertTrue(array.get(0) == null);
            assertTrue(array.get(1).equals("Another string."));
View Full Code Here

     * Test append function to convert an existing value to an array.
     */
    public void test_appendArray() {
        Exception ex = null;
        try {
            JSONObject jObject = new JSONObject();
            JSONArray array = new JSONArray();
            array.add("Hello World.");
            jObject.put("array", array);
            JSONArray array1 = (JSONArray)jObject.get("array");
            assertTrue(array1 != null);
            assertTrue(array1 instanceof JSONArray);
            assertTrue(array1 == array);
            assertTrue(array1.size() == 1);
            jObject.append("array", "Another string.");
            JSONArray array2 = (JSONArray)jObject.get("array");
            assertTrue(array2 != null);
            assertTrue(array2 instanceof JSONArray);
            assertTrue(array1 == array2);
            assertTrue(array2.size() == 2);
        } catch (Exception ex1) {
View Full Code Here


    public void test_EmptyAppend() throws Exception {
        Exception ex = null;
        try {
            JSONObject json = new JSONObject();
            json.append("test", "value");
            JSONArray arr = (JSONArray)json.get("test");
            assertTrue(arr.size() == 1);
            assertTrue(arr.get(0).equals("value"));
        }
        catch (Exception ex1) {
            ex = ex1;
View Full Code Here

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

        try {
            JSONObject jObject = new JSONObject("{\"long\":1}");
            assertTrue(jObject.getLong("long") == 1);

            JSONObject json = new JSONObject("{ Date : 1212790800000 }");
        assertEquals(1212790800000L, json.getLong("Date"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

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

        try {
            JSONObject jObject = new JSONObject("{\"long\":-1}");
            assertTrue(jObject.getLong("long") == -1);
        } 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.