Package org.apache.wink.json4j.compat

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


        try {
            // Verify a malformed JSON string (no closure), fails parse.
            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;
        }
        assertTrue(ex instanceof JSONException);
    }
View Full Code Here


        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 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

        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\": 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

    public void test_putLong() {
        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();
            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

    public void test_putInt() {
        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();
            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

    public void test_putShort() {
        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();
            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

    public void test_putDouble() {
        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();
            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

    public void test_putBoolean() {
        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();
            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

    public void test_putString() {
        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();
            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

    public void test_putJSONObject() {
        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();
            jObject.put("object", factory.createJSONObject());
            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

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.