Search in sources :

Example 11 with DefaultJSONParser

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

the class DateParserTest method test_date_1.

public void test_date_1() throws Exception {
    int features = JSON.DEFAULT_PARSER_FEATURE;
    features = Feature.config(features, Feature.AllowISO8601DateFormat, true);
    DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09T13:49:53.254\"", ParserConfig.getGlobalInstance(), features);
    java.util.Date date = parser.parseObject(java.util.Date.class);
    Assert.assertEquals(new java.util.Date(1294552193254L), date);
    parser.close();
}
Also used : Date(java.util.Date) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 12 with DefaultJSONParser

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

the class DateParserTest method test_date_error_0.

public void test_date_error_0() throws Exception {
    JSONException error = null;
    try {
        DefaultJSONParser parser = new DefaultJSONParser("true");
        parser.parseObject(java.util.Date.class);
        parser.close();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 13 with DefaultJSONParser

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

the class DateParserTest_sql method test_date_3.

public void test_date_3() throws Exception {
    int features = JSON.DEFAULT_PARSER_FEATURE;
    features = Feature.config(features, Feature.AllowISO8601DateFormat, true);
    DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09T13:49:53\"", ParserConfig.getGlobalInstance(), features);
    java.sql.Date date = parser.parseObject(java.sql.Date.class);
    Assert.assertEquals(new java.sql.Date(1294552193000L), date);
    parser.close();
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 14 with DefaultJSONParser

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

the class DateParserTest_sql method test_date_4.

public void test_date_4() throws Exception {
    int features = JSON.DEFAULT_PARSER_FEATURE;
    features = Feature.config(features, Feature.AllowISO8601DateFormat, true);
    DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09\"", ParserConfig.getGlobalInstance(), features);
    java.sql.Date date = parser.parseObject(java.sql.Date.class);
    Assert.assertEquals(new java.sql.Date(1294502400000L), date);
    parser.close();
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 15 with DefaultJSONParser

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

the class DateParserTest_sql_timestamp method test_date_4.

public void test_date_4() throws Exception {
    int features = JSON.DEFAULT_PARSER_FEATURE;
    features = Feature.config(features, Feature.AllowISO8601DateFormat, true);
    DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09\"", ParserConfig.getGlobalInstance(), features);
    java.sql.Timestamp date = parser.parseObject(java.sql.Timestamp.class);
    Assert.assertEquals(new java.sql.Timestamp(1294502400000L), date);
    parser.close();
}
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