use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_constructor.
public void test_constructor() throws Exception {
List<Object> list = new ArrayList();
JSONArray array = new JSONArray(list);
array.add(3);
Assert.assertEquals(1, list.size());
Assert.assertEquals(3, list.get(0));
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONArrayTest method test_getObject_null.
public void test_getObject_null() throws Exception {
JSONArray array = new JSONArray();
array.add(null);
Assert.assertTrue(array.getJSONObject(0) == null);
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class LexerTest method test_number.
public void test_number() throws Exception {
String text = "[0,1,-1,2E3,2E+3,2E-3,2e3,2e+3,2e-3]";
JSONArray array = JSON.parseArray(text);
Assert.assertEquals(0, array.get(0));
Assert.assertEquals(1, array.get(1));
Assert.assertEquals(-1, array.get(2));
Assert.assertEquals(new BigDecimal("2E3"), array.get(3));
Assert.assertEquals(new BigDecimal("2E3"), array.get(4));
Assert.assertEquals(new BigDecimal("2E-3"), array.get(5));
Assert.assertEquals(new BigDecimal("2E3"), array.get(6));
Assert.assertEquals(new BigDecimal("2E3"), array.get(7));
Assert.assertEquals(new BigDecimal("2E-3"), array.get(8));
for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE + 1000 * 10; ++i) {
Assert.assertEquals(i, JSON.parse(Long.toString(i)));
}
for (long i = Long.MAX_VALUE - 1000 * 10; i <= Long.MAX_VALUE && i > 0; ++i) {
Assert.assertEquals(i, JSON.parse(Long.toString(i)));
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Bug_for_issue_434 method test_for_issue.
public void test_for_issue() throws Exception {
String json = "{value:[\"null\"]}";
JSONObject parse = JSONObject.parseObject(json);
JSONArray jsonArray = parse.getJSONArray("value");
Assert.assertEquals(1, jsonArray.size());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Bug_for_issue_430 method test_for_issue_1.
public void test_for_issue_1() throws Exception {
String text = "[{\"@type\": \"com.alibaba.json.bvt.bug.Bug_for_issue_430$FooModel\", \"fooCollection\": null}, {\"@type\": \"com.alibaba.json.bvt.bug.Bug_for_issue_430$FooModel\", \"fooCollection\": null}]";
JSONArray array = (JSONArray) JSON.parse(text);
Assert.assertEquals(FooModel.class, array.get(0).getClass());
Assert.assertEquals(FooModel.class, array.get(1).getClass());
Assert.assertNull(((FooModel) array.get(0)).fooCollection);
Assert.assertNull(((FooModel) array.get(1)).fooCollection);
}
Aggregations