Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONObject


    }

    public void test_writeJSONString() throws Exception {
        {
            StringWriter out = new StringWriter();
            new JSONObject().writeJSONString(out);
            Assert.assertEquals("{}", out.toString());
        }
    }
View Full Code Here


            Assert.assertEquals("{}", out.toString());
        }
    }

    public void test_getLong() throws Exception {
        JSONObject json = new JSONObject(true);
        json.put("A", 55L);
        json.put("B", 55);
        json.put("K", true);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);
        Assert.assertEquals(json.getLong("B").longValue(), 55L);
        Assert.assertEquals(json.getLong("C"), null);
        Assert.assertEquals(json.getBooleanValue("K"), true);
        Assert.assertEquals(json.getBoolean("K"), Boolean.TRUE);
    }
View Full Code Here

        Assert.assertTrue(map == TypeUtils.castToJavaBean(map, Map.class));
    }

    public void test_1() throws Exception {
        JSONObject map = new JSONObject();
        Assert.assertTrue(map == TypeUtils.castToJavaBean(map, Map.class));
    }
View Full Code Here

        JSONObject map = new JSONObject();
        Assert.assertTrue(map == TypeUtils.castToJavaBean(map, Map.class));
    }

    public void test_2() throws Exception {
        JSONObject map = new JSONObject();
        map.put("id", 1);
        map.put("name", "panlei");

        User user = TypeUtils.castToJavaBean(map, User.class);
        Assert.assertEquals(1L, user.getId());
        Assert.assertEquals("panlei", user.getName());
    }
View Full Code Here

        Assert.assertEquals(json.getBooleanValue("K"), true);
        Assert.assertEquals(json.getBoolean("K"), Boolean.TRUE);
    }

    public void test_getLong_1() throws Exception {
        JSONObject json = new JSONObject(false);
        json.put("A", 55L);
        json.put("B", 55);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);
        Assert.assertEquals(json.getLong("B").longValue(), 55L);
        Assert.assertEquals(json.getLong("C"), null);
    }
View Full Code Here

        Assert.assertEquals(1L, user.getId());
        Assert.assertEquals("panlei", user.getName());
    }

    public void test_cast_Integer() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1L);
        Assert.assertEquals(new Integer(1), json.getObject("id", int.class));
    }
View Full Code Here

        json.put("id", 1L);
        Assert.assertEquals(new Integer(1), json.getObject("id", int.class));
    }

    public void test_cast_Integer_2() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1L);
        Assert.assertEquals(new Integer(1), json.getObject("id", Integer.class));
    }
View Full Code Here

        Assert.assertEquals(json.getLong("C"), null);
    }

    public void test_getDate() throws Exception {
        long currentTimeMillis = System.currentTimeMillis();
        JSONObject json = new JSONObject();
        json.put("A", new Date(currentTimeMillis));
        json.put("B", currentTimeMillis);
        Assert.assertEquals(json.getDate("A").getTime(), currentTimeMillis);
        Assert.assertEquals(json.getDate("B").getTime(), currentTimeMillis);
        Assert.assertEquals(json.getLong("C"), null);
    }
View Full Code Here

        json.put("id", 1L);
        Assert.assertEquals(new Integer(1), json.getObject("id", Integer.class));
    }

    public void test_cast_to_long() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Long(1), json.getObject("id", long.class));
    }
View Full Code Here

        json.put("id", 1);
        Assert.assertEquals(new Long(1), json.getObject("id", long.class));
    }

    public void test_cast_to_Long() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Long(1), json.getObject("id", Long.class));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.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.