use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class DefaultExtJSONParserTest_2 method test_error_3.
public void test_error_3() throws Exception {
JSONException error = null;
try {
DefaultJSONParser parser = new DefaultJSONParser("{");
parser.config(Feature.AllowUnQuotedFieldNames, true);
parser.parseObject(A.class);
} catch (JSONException e) {
error = e;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class DefaultExtJSONParserTest_4 method test_1.
public void test_1() throws Exception {
JSONObject res = new JSONObject();
res.put("a", 1);
res.put("b", 2);
res.put("c", 3);
String[] tests = { "{ 'a':1, 'b':2, 'c':3 }", "{ 'a':1,,'b':2, 'c':3 }", "{,'a':1, 'b':2, 'c':3 }", "{'a':1, 'b':2, 'c':3,,}", "{,,'a':1,,,,'b':2,'c':3,,,,,}" };
for (String t : tests) {
DefaultJSONParser ext = new DefaultJSONParser(t);
ext.config(Feature.AllowArbitraryCommas, true);
JSONObject extRes = ext.parseObject();
Assert.assertEquals(res, extRes);
DefaultJSONParser basic = new DefaultJSONParser(t);
basic.config(Feature.AllowArbitraryCommas, true);
JSONObject basicRes = basic.parseObject();
Assert.assertEquals(res, basicRes);
}
}
use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class DefaultExtJSONParserTest_4 method test_2.
public void test_2() throws Exception {
A res = new A();
res.setA(1);
res.setB(2);
res.setC(3);
String[] tests = { "{ 'a':1, 'b':2, 'c':3 }", "{ 'a':1,,'b':2, 'c':3 }", "{,'a':1, 'b':2, 'c':3 }", "{'a':1, 'b':2, 'c':3,,}", "{,,'a':1,,,,'b':2,,'c':3,,,,,}" };
for (String t : tests) {
DefaultJSONParser ext = new DefaultJSONParser(t);
ext.config(Feature.AllowArbitraryCommas, true);
A extRes = ext.parseObject(A.class);
Assert.assertEquals(res, extRes);
}
}
use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.
the class JSONReaderScannerTest__entity_boolean 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(',');
}
//
if (i % 2 == 0) {
buf.append("{\"id\":true}");
} else {
buf.append("{\"id\":false}");
}
}
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) {
if (i % 2 == 0) {
Assert.assertEquals(true, array.get(i).getId());
} else {
Assert.assertEquals(false, array.get(i).getId());
}
}
}
use of com.alibaba.fastjson.parser.DefaultJSONParser 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();
}
Aggregations