Package org.apache.wink.json4j.compat

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


    public void test_JoinNoDelimiter() {
        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();
            JSONArray jArray = factory.createJSONArray("[1, true, false, null, \"My String\", [1,2,3], {\"foo\":\"bar\"}]");
            String joined = jArray.join("");
            assertTrue(joined.equals("1truefalsenullMy String[1,2,3]{\"foo\":\"bar\"}"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here


    public void test_JoinDelimiter() {
        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();
            JSONArray jArray = factory.createJSONArray("[1, true, false, null, \"My String\", [1,2,3], {\"foo\":\"bar\"}]");
            String joined = jArray.join("|");
            assertTrue(joined.equals("1|true|false|null|My String|[1,2,3]|{\"foo\":\"bar\"}"));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

        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();
            jObject.put("array", factory.createJSONArray());
            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;
View Full Code Here

            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

            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");

            System.out.println("Array size: " + array.length());
            for (int i = 0; i < array.length(); i++) {
                System.out.println("Val at location: [" + i + "] is: " + array.get(i));
            }

            assertTrue(array != null);
            assertTrue(array instanceof JSONArray);
            assertTrue(array.length() == 2);
            assertTrue(array.get(0) == null);
            assertTrue(array.get(1).equals("Another string."));
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

        try {
            System.out.println("In: test_appendArray");
            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();
            JSONArray array = factory.createJSONArray();
            array.put("Hello World.");
            jObject.put("array", array);
            JSONArray array1 = (JSONArray)jObject.get("array");
            assertTrue(array1 != null);
            assertTrue(array1 instanceof JSONArray);
            assertTrue(array1.length() == 1);
            jObject.append("array", "Another string.");
            JSONArray array2 = (JSONArray)jObject.get("array");
            assertTrue(array2 != null);
            assertTrue(array2 instanceof JSONArray);
            assertTrue(array2.length() == 2);
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

            JSONWriter jWriter = factory.createJSONWriter(w);
            jWriter.array();
            jWriter.endArray();
            String str = w.toString();
            // Verify it parses.
            JSONArray test = factory.createJSONArray(str);
            assertTrue(str.equals("[]"));
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

            jWriter.array();
            jWriter.close();

            String str = w.toString();
            // Verify it parses.
            JSONArray test = factory.createJSONArray(str);
            assertTrue(str.equals("[]"));
        }catch(Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

            JSONWriter jWriter = factory.createJSONWriter(w);
            jWriter.object();
            jWriter.key("foo");

            // Verify we can put a JSONObject into the stream!
            JSONArray jArray = factory.createJSONArray();
            jArray.put(true);
            jWriter.value(jArray);

            jWriter.endObject();
            jWriter.close();
View Full Code Here

            jWriter.close();
            String str = w.toString();

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

TOP

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