Search in sources :

Example 46 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray_2 method test_error_1.

public void test_error_1() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[['1']]");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Exception error = null;
    try {
        parser.parseArrayWithType(new TypeReference<Map<?, ?>>() {
        }.getType());
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) TypeReference(com.alibaba.fastjson.TypeReference)

Example 47 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray_2 method test_error_5.

public void test_error_5() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[]");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Assert.assertEquals(1, parser.parseArray(new Type[] { Integer[].class }).length);
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 48 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray_2 method test_error_0.

public void test_error_0() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("['1','2'}");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Exception error = null;
    try {
        List<Object> list = new ArrayList<Object>();
        parser.parseArray(Integer.class, list);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : ArrayList(java.util.ArrayList) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 49 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray_2 method test_1.

public void test_1() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("['1','2']");
    parser.config(Feature.AllowISO8601DateFormat, false);
    List<Object> list = new ArrayList<Object>();
    parser.parseArray(Integer.class, list);
    Assert.assertEquals(new Integer(1), list.get(0));
    Assert.assertEquals(new Integer(2), list.get(1));
}
Also used : ArrayList(java.util.ArrayList) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 50 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray_2 method test_error_6.

public void test_error_6() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("['1' 1 '2'}");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Exception error = null;
    try {
        parser.parseArray(new Type[] { Integer.class });
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : 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