Search in sources :

Example 51 with DefaultJSONParser

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

the class DefaultJSONParserTest_date method test_date2.

public void test_date2() {
    String text = "{\"date\":\"xxxxx\"}";
    char[] chars = text.toCharArray();
    DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
    parser.config(Feature.AllowISO8601DateFormat, true);
    JSONObject json = parser.parseObject();
    Assert.assertEquals("xxxxx", json.get("date"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 52 with DefaultJSONParser

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

the class DefaultJSONParserTest_date method test_dateFormat.

public void test_dateFormat() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("{}");
    parser.setDateFormat("yyyy-DD-mm");
    SimpleDateFormat format = new SimpleDateFormat("yyyy-DD-mm", JSON.defaultLocale);
    format.setTimeZone(JSON.defaultTimeZone);
    parser.setDateFormat(format);
    parser.getDateFomartPattern();
    parser.getDateFormat();
    parser.parse();
    parser.close();
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with DefaultJSONParser

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

the class DefaultJSONParserTest_date method test_date3.

public void test_date3() {
    String text = "{\"1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\\t\":\"xxxxx\"}";
    char[] chars = text.toCharArray();
    DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
    parser.config(Feature.AllowISO8601DateFormat, true);
    JSONObject json = parser.parseObject();
    Assert.assertEquals("xxxxx", json.get("1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\t"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 54 with DefaultJSONParser

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

the class DefaultJSONParserTest_date method test_date4.

public void test_date4() {
    String text = "{\"1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\\t\":\"xxxxx\"}";
    char[] chars = text.toCharArray();
    DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
    parser.config(Feature.AllowISO8601DateFormat, true);
    JSONObject json = parser.parseObject();
    Assert.assertEquals("xxxxx", json.get("1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\t"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

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

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