use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_getArray.
public void test_getArray() throws Exception {
JSONArray array = new JSONArray();
array.add(new ArrayList());
Assert.assertEquals(0, array.getJSONArray(0).size());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_getObject_map.
public void test_getObject_map() throws Exception {
JSONArray array = new JSONArray();
array.add(new HashMap());
Assert.assertEquals(0, array.getJSONObject(0).size());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_getObject.
public void test_getObject() throws Exception {
JSONArray array = new JSONArray();
array.add(new JSONObject());
Assert.assertEquals(0, array.getJSONObject(0).size());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_getJavaBean.
public void test_getJavaBean() throws Exception {
JSONArray array = JSON.parseArray("[{id:123, name:'aaa'}]");
Assert.assertEquals(1, array.size());
Assert.assertEquals(123, array.getObject(0, User.class).getId());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_2.
public void test_2() throws Exception {
JSONArray array = new JSONArray();
array.add(123);
array.add("222");
array.add(3);
array.add(true);
array.add("true");
array.add(null);
Assert.assertEquals(123, array.getByte(0).byteValue());
Assert.assertEquals(123, array.getByteValue(0));
Assert.assertEquals(123, array.getShort(0).shortValue());
Assert.assertEquals(123, array.getShortValue(0));
Assert.assertTrue(123F == array.getFloat(0).floatValue());
Assert.assertTrue(123F == array.getFloatValue(0));
Assert.assertTrue(123D == array.getDouble(0).doubleValue());
Assert.assertTrue(123D == array.getDoubleValue(0));
Assert.assertEquals(123, array.getIntValue(0));
Assert.assertEquals(123, array.getLongValue(0));
Assert.assertEquals(new BigDecimal("123"), array.getBigDecimal(0));
Assert.assertEquals(222, array.getIntValue(1));
Assert.assertEquals(new Integer(222), array.getInteger(1));
Assert.assertEquals(new Long(222), array.getLong(1));
Assert.assertEquals(new BigDecimal("222"), array.getBigDecimal(1));
Assert.assertEquals(true, array.getBooleanValue(4));
Assert.assertEquals(Boolean.TRUE, array.getBoolean(4));
Assert.assertEquals(0, array.getIntValue(5));
Assert.assertEquals(0, array.getLongValue(5));
Assert.assertEquals(null, array.getInteger(5));
Assert.assertEquals(null, array.getLong(5));
Assert.assertEquals(null, array.getBigDecimal(5));
Assert.assertEquals(null, array.getBoolean(5));
Assert.assertEquals(false, array.getBooleanValue(5));
}
Aggregations