use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest__entity_stringList 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("{\"id\":[\"" + i + "\",\"" + (10000 + i) + "\"]}");
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
List<VO> array = parser.parseArray(VO.class);
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(2, array.get(i).getId().size());
Assert.assertEquals(Integer.toString(i), array.get(i).getId().get(0));
Assert.assertEquals(Integer.toString(10000 + i), array.get(i).getId().get(1));
}
}
use of com.alibaba.fastjson.parser.JSONReaderScanner 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.parser.JSONReaderScanner 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.parser.JSONReaderScanner 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.parser.JSONReaderScanner in project fastjson by alibaba.
the class DateTest method test_reader.
public void test_reader() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"date\":\"2012/04-01\"}", 0));
parser.setDateFormat("yyyy/MM-dd");
VO vo = parser.parseObject(VO.class);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM-dd", JSON.defaultLocale);
dateFormat.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals(dateFormat.parse("2012/04-01"), vo.getDate());
parser.close();
}
Aggregations