Search in sources :

Example 86 with DefaultJSONParser

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());
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) Map(java.util.Map)

Example 87 with DefaultJSONParser

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);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 88 with DefaultJSONParser

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);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 89 with DefaultJSONParser

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());
    }
}
Also used : StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 90 with DefaultJSONParser

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());
    }
}
Also used : StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Aggregations

DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)258 JSONObject (com.alibaba.fastjson.JSONObject)42 JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)35 JSONException (com.alibaba.fastjson.JSONException)29 ArrayList (java.util.ArrayList)21 Reader (java.io.Reader)14 StringReader (java.io.StringReader)14 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)11 BigDecimal (java.math.BigDecimal)10 Date (java.util.Date)10 Feature (com.alibaba.fastjson.parser.Feature)9 List (java.util.List)9 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)8 Type (java.lang.reflect.Type)7 JSONArray (com.alibaba.fastjson.JSONArray)6 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)5 ObjectDeserializer (com.alibaba.fastjson.parser.deserializer.ObjectDeserializer)5 TypeUtils.castToString (com.alibaba.fastjson.util.TypeUtils.castToString)5 LinkedHashMap (java.util.LinkedHashMap)5 MiscCodec (com.alibaba.fastjson.serializer.MiscCodec)4