Search in sources :

Example 76 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray method test_17.

public void test_17() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[]");
    Object[] array = parser.parseArray(new Type[] { Integer[].class });
    Integer[] values = (Integer[]) array[0];
    Assert.assertEquals(0, values.length);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 77 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray method test_18.

public void test_18() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("null");
    parser.config(Feature.AllowISO8601DateFormat, false);
    List<Integer> list = (List<Integer>) parser.parseArrayWithType(new TypeReference<List<Integer>>() {
    }.getType());
    Assert.assertEquals(null, list);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 78 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray method test_error_7.

public void test_error_7() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("{1}");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Exception error = null;
    try {
        parser.parseArray(new Type[] {});
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 79 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray method test_3.

public void test_3() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,2,3]");
    parser.config(Feature.AllowArbitraryCommas, true);
    List list = new ArrayList();
    parser.parseArray(BigDecimal.class, list);
    Assert.assertEquals("[1, 2, 3]", list.toString());
    Assert.assertEquals(new BigDecimal("1"), list.get(0));
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) BigDecimal(java.math.BigDecimal)

Example 80 with DefaultJSONParser

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

the class DefaultExtJSONParser_parseArray method test_10.

public void test_10() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,2,3]");
    Object[] array = parser.parseArray(new Type[] { Integer[].class });
    Integer[] values = (Integer[]) array[0];
    Assert.assertEquals(new Integer(1), values[0]);
    Assert.assertEquals(new Integer(2), values[1]);
    Assert.assertEquals(new Integer(3), values[2]);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) 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