use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class DefaultJSONParserTest2 method test_5.
public void test_5() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("{}");
Map map = parser.parseObject();
Assert.assertEquals(0, map.size());
}
use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class DefaultJSONParserTest_comma method test_getInput.
public void test_getInput() {
String text = "{,,}";
char[] chars = text.toCharArray();
DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
JSONException error = null;
try {
parser.parseObject();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class DefaultJSONParserTest_error method test_error_2.
public void test_error_2() {
String text = "{\"obj\":[]]}";
char[] chars = text.toCharArray();
DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
JSONException error = null;
try {
parser.parseObject();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.parser.DefaultJSONParser 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.DefaultJSONParser in project fastjson by alibaba.
the class JSONReaderScannerTest__entity_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("{\"id\":\"" + 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(Integer.toString(i), array.get(i).getId());
}
}
Aggregations