use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest method test_doubleQuote.
public void test_doubleQuote() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"name\":\"张三\\'\\n\\r\\\"\"}"));
JSONObject json = parser.parseObject();
Assert.assertEquals("张三\'\n\r\"", json.get("name"));
parser.close();
}
use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONLexerAllowCommentTest method test_0.
public void test_0() throws Exception {
String jsonWithComment = "{ /*tes****\n\r\n*t*/\"a\":1 /*****test88888*****/ /*test*/ , /*test*/ //test\n //est\n \"b\":2}";
JSONObject object = JSON.parseObject(jsonWithComment, Feature.AllowComment, Feature.OrderedField);
System.out.println(object.toJSONString());
Assert.assertEquals("{\"a\":1,\"b\":2}", object.toJSONString());
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(jsonWithComment, Feature.AllowComment.getMask() | Feature.OrderedField.getMask()));
JSONObject object1 = parser.parseObject();
Assert.assertEquals("{\"a\":1,\"b\":2}", object1.toJSONString());
System.out.println(object1.toJSONString());
}
use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest__map_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);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(Integer.toString(i), array.getJSONObject(i).get("id"));
}
}
use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONReaderScannerTest_long 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(',');
}
long value = (long) Integer.MAX_VALUE + 1L + (long) i;
buf.append(value);
}
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) {
long value = (long) Integer.MAX_VALUE + 1L + (long) i;
Assert.assertEquals(value, ((Long) array.get(i)).longValue());
}
}
use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.
the class JSONLexerTest_8 method test_ident_3.
public void test_ident_3() throws Exception {
JSONReaderScanner lexer = new JSONReaderScanner("123");
lexer.nextIdent();
org.junit.Assert.assertEquals(JSONToken.LITERAL_INT, lexer.token());
lexer.close();
}
Aggregations