Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONObject


        json.put("id", 1);
        Assert.assertEquals(Boolean.TRUE, json.getObject("id", boolean.class));
    }

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


        json.put("id", 1);
        Assert.assertEquals(Boolean.TRUE, json.getObject("id", Boolean.class));
    }

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

        Assert.assertEquals(0L, json.getLongValue("D"));
        Assert.assertEquals(false, json.getBooleanValue("D"));
    }

    public void test_all() throws Exception {
        JSONObject json = new JSONObject();
        Assert.assertEquals(true, json.isEmpty());
        json.put("C", 51L);
        json.put("B", 52);
        json.put("A", 53);
        Assert.assertEquals(false, json.isEmpty());
        Assert.assertEquals(true, json.containsKey("C"));
        Assert.assertEquals(false, json.containsKey("D"));
        Assert.assertEquals(true, json.containsValue(52));
        Assert.assertEquals(false, json.containsValue(33));
        Assert.assertEquals(null, json.remove("D"));
        Assert.assertEquals(51L, json.remove("C"));
        Assert.assertEquals(2, json.keySet().size());
        Assert.assertEquals(2, json.values().size());
        Assert.assertEquals(new BigDecimal("53"), json.getBigDecimal("A"));

        json.putAll(Collections.singletonMap("E", 99));
        Assert.assertEquals(3, json.values().size());
        json.clear();
        Assert.assertEquals(0, json.values().size());
        json.putAll(Collections.singletonMap("E", 99));
        Assert.assertEquals(99L, json.getLongValue("E"));
        Assert.assertEquals(99, json.getIntValue("E"));
        Assert.assertEquals("99", json.getString("E"));
        Assert.assertEquals(null, json.getString("F"));
        Assert.assertEquals(null, json.getDate("F"));
        Assert.assertEquals(null, json.getBoolean("F"));
    }
View Full Code Here

        json.put("id", null);
        Assert.assertEquals(null, json.getObject("id", Boolean.class));
    }

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

    }

    public void test_cast_to_Date() throws Exception {
        long millis = System.currentTimeMillis();

        JSONObject json = new JSONObject();
        json.put("date", millis);
        Assert.assertEquals(new Date(millis), json.getObject("date", Date.class));
    }
View Full Code Here

    }

    public void test_cast_to_SqlDate() throws Exception {
        long millis = System.currentTimeMillis();

        JSONObject json = new JSONObject();
        json.put("date", millis);
        Assert.assertEquals(new java.sql.Date(millis), json.getObject("date", java.sql.Date.class));
    }
View Full Code Here

    }

    public void test_cast_to_SqlDate_string() throws Exception {
        long millis = System.currentTimeMillis();

        JSONObject json = new JSONObject();
        json.put("date", Long.toString(millis));
        Assert.assertEquals(new java.sql.Date(millis), json.getObject("date", java.sql.Date.class));
    }
View Full Code Here

        json.put("date", Long.toString(millis));
        Assert.assertEquals(new java.sql.Date(millis), json.getObject("date", java.sql.Date.class));
    }

    public void test_cast_to_SqlDate_null() throws Exception {
        JSONObject json = new JSONObject();
        json.put("date", null);
        Assert.assertEquals(null, json.getObject("date", java.sql.Date.class));
    }
View Full Code Here

    }

    public void test_cast_to_SqlDate_util_Date() throws Exception {
        long millis = System.currentTimeMillis();

        JSONObject json = new JSONObject();
        json.put("date", new Date(millis));
        Assert.assertEquals(new java.sql.Date(millis), json.getObject("date", java.sql.Date.class));
    }
View Full Code Here

    }

    public void test_cast_to_SqlDate_sql_Date() throws Exception {
        long millis = System.currentTimeMillis();

        JSONObject json = new JSONObject();
        json.put("date", new java.sql.Date(millis));
        Assert.assertEquals(new java.sql.Date(millis), json.getObject("date", java.sql.Date.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.