Search in sources :

Example 96 with JSONObject

use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.

the class TypeUtilsTest method test_cast_to_BigDecimal.

public void test_cast_to_BigDecimal() throws Exception {
    JSONObject json = new JSONObject();
    json.put("id", 1);
    Assert.assertEquals(new BigDecimal("1"), json.getObject("id", BigDecimal.class));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BigDecimal(java.math.BigDecimal)

Example 97 with JSONObject

use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.

the class TypeUtilsTest method test_cast_to_Timestamp_util_Date.

public void test_cast_to_Timestamp_util_Date() throws Exception {
    long millis = System.currentTimeMillis();
    JSONObject json = new JSONObject();
    json.put("date", new Date(millis));
    Assert.assertEquals(new java.sql.Timestamp(millis), json.getObject("date", java.sql.Timestamp.class));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Date(java.util.Date)

Example 98 with JSONObject

use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.

the class TypeUtilsTest method test_cast_to_Timestamp.

public void test_cast_to_Timestamp() throws Exception {
    long millis = System.currentTimeMillis();
    JSONObject json = new JSONObject();
    json.put("date", millis);
    Assert.assertEquals(new java.sql.Timestamp(millis), json.getObject("date", java.sql.Timestamp.class));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 99 with JSONObject

use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.

the class TypeUtilsTest method test_2.

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());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 100 with JSONObject

use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.

the class TestUTF8 method test_utf_.

public void test_utf_() throws Exception {
    String content = "Viel Spaß mit Java 7 und Eclipse!";
    JSONObject json = new JSONObject();
    json.put("content", content);
    JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
    Assert.assertEquals(1, obj.size());
    Assert.assertEquals(content, obj.get("content"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)354 JSONArray (com.alibaba.fastjson.JSONArray)35 Test (org.junit.Test)29 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)23 HashMap (java.util.HashMap)19 JSONException (com.alibaba.fastjson.JSONException)18 ArrayList (java.util.ArrayList)18 Date (java.util.Date)17 JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)14 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)11 JSMethod (com.taobao.weex.annotation.JSMethod)11 IOException (java.io.IOException)11 Map (java.util.Map)11 WXBridgeManagerTest (com.taobao.weex.bridge.WXBridgeManagerTest)9 BigDecimal (java.math.BigDecimal)9 List (java.util.List)7 Gson (com.google.gson.Gson)6 BigInteger (java.math.BigInteger)5 Activity (android.app.Activity)4 JSONPObject (com.alibaba.fastjson.JSONPObject)4