use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest__entity_double_2 method test_scanFloat.
public void test_scanFloat() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 1024; ++i) {
if (i != 0) {
buf.append(',');
}
buf.append("{\"id\":" + i + ".0}");
}
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.assertTrue(Integer.toString(i), (double) i == array.get(i).getId());
}
parser.close();
}
use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest__entity_enum 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
//
Type type;
if (i % 3 == 0) {
type = Type.A;
} else if (i % 3 == 1) {
type = Type.AA;
} else {
type = Type.AAA;
}
buf.append("{\"id\":\"" + type.name() + "\"}");
}
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) {
Type type;
if (i % 3 == 0) {
type = Type.A;
} else if (i % 3 == 1) {
type = Type.AA;
} else {
type = Type.AAA;
}
Assert.assertEquals(type, array.get(i).getId());
}
}
use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest__entity_long 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
//
long value = (long) 1000000000000L + 1L + (long) i;
buf.append("{\"id\":" + value + "}");
}
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) {
long value = (long) 1000000000000L + 1L + (long) i;
Assert.assertEquals(value, array.get(i).getId());
}
}
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 JSONReaderScannerTest_boolean method test_true.
public void test_true() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"name\":true}"));
JSONObject json = parser.parseObject();
Assert.assertEquals(Boolean.TRUE, json.get("name"));
parser.close();
}
Aggregations