use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Issue922 method test_for_issue.
public void test_for_issue() throws Exception {
String text = "[1,2,3]";
JSONArray array = JSON.parseArray(text);
List<Long> list = array.toJavaList(Long.class);
assertEquals(1L, list.get(0).longValue());
assertEquals(2L, list.get(1).longValue());
assertEquals(3L, list.get(2).longValue());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest_array_string method test_scanInt.
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 10; ++i) {
if (i != 0) {
buf.append(',');
}
// 1000000000000
//
buf.append("\"" + i + "\"");
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(Integer.toString(i), array.get(i));
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest_decimal method test_scanInt.
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 1024; ++i) {
if (i != 0) {
buf.append(',');
}
buf.append(i + ".0");
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
BigDecimal value = new BigDecimal(i + ".0");
Assert.assertEquals(value, array.get(i));
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest_int method test_scanInt.
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 1024; ++i) {
if (i != 0) {
buf.append(',');
}
buf.append(i);
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(i, ((Integer) array.get(i)).intValue());
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class TypeUtilsTest3 method test_ex.
public void test_ex() throws Exception {
RuntimeException ex = new RuntimeException();
JSONObject object = (JSONObject) JSON.toJSON(ex);
JSONArray array = object.getJSONArray("stackTrace");
array.getJSONObject(0).put("lineNumber", null);
JSON.parseObject(object.toJSONString(), Exception.class);
}
Aggregations