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"));
}
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();
}
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"));
}
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"));
}
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);
}
Aggregations