Package org.apache.wink.json4j.compat

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


        JSONArray jArray = 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();
            jArray = factory.createJSONArray("[\"foo\", \"bar\", \"bool\", true]");
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here


        Exception ex = null;
        // read in a basic JSON file of a toplevel array that has all the various types in it.
        try {
            Reader rdr = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("utf8_basic_array.json"), "UTF-8");
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            jArray = factory.createJSONArray(rdr);
            rdr.close();
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
        }
View Full Code Here

        JSONArray jArray = null;
        Exception ex = null;
        // Load a basic JSON string that's corrupt
        try {
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            jArray = factory.createJSONArray("[\"foo\", bar}, \"bool\", true]");
        } catch (Exception ex1) {
            ex = ex1;
        }
        assertTrue(ex != null);
        assertTrue(ex instanceof JSONException);
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();
            JSONArray jArray = factory.createJSONArray();
            jArray.put((long)1);
            Long l = (Long)jArray.get(0);
            assertTrue(l != null);
            assertTrue(l instanceof java.lang.Long);
            assertTrue(jArray.getLong(0) == 1);
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();
            JSONArray jArray = factory.createJSONArray();
            jArray.put(1);
            Integer i = (Integer)jArray.get(0);
            assertTrue(i != null);
            assertTrue(i instanceof java.lang.Integer);
            assertTrue(jArray.getInt(0) == 1);
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();
            JSONArray jArray = factory.createJSONArray();
            jArray.put((short)1);
            Short s = (Short)jArray.get(0);
            assertTrue(s != null);
            assertTrue(s instanceof java.lang.Short);
            assertTrue(jArray.getShort(0) == 1);
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();
            JSONArray jArray = factory.createJSONArray();
            jArray.put((double)1.123);
            Double d = (Double)jArray.get(0);
            assertTrue(d != null);
            assertTrue(d instanceof java.lang.Double);
            assertTrue(jArray.getDouble(0) == 1.123);
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();
            JSONArray jArray = factory.createJSONArray();
            jArray.put(true);
            Boolean b = (Boolean)jArray.get(0);
            assertTrue(b != null);
            assertTrue(b instanceof java.lang.Boolean);
            assertTrue(jArray.getBoolean(0) == true);
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();
            JSONArray jArray = factory.createJSONArray();
            jArray.put("Hello World.");
            String s = (String)jArray.get(0);
            assertTrue(s != null);
            assertTrue(s instanceof java.lang.String);
            assertTrue(jArray.getString(0).equals("Hello World."));
View Full Code Here

     */
    public void test_putNull() {
        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();
            jArray.put((Object)null);
            String s = (String)jArray.get(0);
            assertTrue(s == null);
        } catch (Exception ex1) {
            ex = ex1;
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.compat.JSONFactory

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.