Search in sources :

Example 56 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 57 with DefaultJSONParser

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

the class DateParserTest method test_date_new.

public void test_date_new() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)");
    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 58 with DefaultJSONParser

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

the class DateParserTest method test_date_new_1.

public void test_date_new_1() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)");
    java.util.Date date = (java.util.Date) parser.parse();
    Assert.assertEquals(new java.util.Date(1294552193254L), date);
    parser.close();
}
Also used : Date(java.util.Date) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) Date(java.util.Date)

Example 59 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)

Example 60 with DefaultJSONParser

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

the class DateParserTest_sql_timestamp method test_date_2.

public void test_date_2() throws Exception {
    int features = JSON.DEFAULT_PARSER_FEATURE;
    DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)", ParserConfig.getGlobalInstance(), features);
    java.sql.Timestamp date = parser.parseObject(java.sql.Timestamp.class);
    Assert.assertEquals(new java.sql.Timestamp(1294552193254L), date);
    parser.close();
}
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