Search in sources :

Example 41 with DefaultJSONParser

use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.

the class DefaultExtJSONParserTest_2 method test_error_6.

public void test_error_6() throws Exception {
    JSONException error = null;
    try {
        DefaultJSONParser parser = new DefaultJSONParser("{'a':3}");
        parser.config(Feature.AllowSingleQuotes, false);
        parser.parseObject(A.class);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 42 with DefaultJSONParser

use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.

the class DefaultExtJSONParserTest_2 method test_error_0.

public void test_error_0() throws Exception {
    Exception error = null;
    try {
        String text = "[{\"old\":false,\"name\":\"校长\",\"age\":3,\"salary\":123456789.0123]";
        DefaultJSONParser parser = new DefaultJSONParser(text);
        parser.parseArray(User.class);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) JSONException(com.alibaba.fastjson.JSONException)

Example 43 with DefaultJSONParser

use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.

the class DefaultExtJSONParserTest_2 method test_2.

public void test_2() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("{a:3}");
    parser.config(Feature.AllowUnQuotedFieldNames, true);
    Map a = parser.parseObject(Map.class);
    Assert.assertEquals(3, a.get("a"));
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 44 with DefaultJSONParser

use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.

the class DefaultExtJSONParserTest_2 method test_error_2.

public void test_error_2() throws Exception {
    JSONException error = null;
    try {
        DefaultJSONParser parser = new DefaultJSONParser("{a 3}");
        parser.config(Feature.AllowUnQuotedFieldNames, true);
        parser.parseObject(A.class);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 45 with DefaultJSONParser

use of com.alibaba.fastjson.parser.DefaultJSONParser in project fastjson by alibaba.

the class DefaultExtJSONParserTest_3 method test_4.

public void test_4() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("{v5:'3'}");
    parser.config(Feature.AllowUnQuotedFieldNames, true);
    parser.config(Feature.AllowSingleQuotes, true);
    A a = parser.parseObject(A.class);
    Assert.assertEquals(3L, a.getV5().longValue());
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Aggregations

DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)242 JSONObject (com.alibaba.fastjson.JSONObject)35 JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)34 JSONException (com.alibaba.fastjson.JSONException)28 ArrayList (java.util.ArrayList)21 Reader (java.io.Reader)14 StringReader (java.io.StringReader)14 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)10 BigDecimal (java.math.BigDecimal)10 Date (java.util.Date)10 List (java.util.List)9 Feature (com.alibaba.fastjson.parser.Feature)6 JSONArray (com.alibaba.fastjson.JSONArray)5 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)5 TypeUtils.castToString (com.alibaba.fastjson.util.TypeUtils.castToString)5 MiscCodec (com.alibaba.fastjson.serializer.MiscCodec)4 LinkedHashMap (java.util.LinkedHashMap)4 TypeReference (com.alibaba.fastjson.TypeReference)3 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)3 NumberDeserializer (com.alibaba.fastjson.parser.deserializer.NumberDeserializer)3