本文整理汇总了Java中com.alibaba.fastjson.parser.JSONScanner.getCalendar方法的典型用法代码示例。如果您正苦于以下问题:Java JSONScanner.getCalendar方法的具体用法?Java JSONScanner.getCalendar怎么用?Java JSONScanner.getCalendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.JSONScanner
的用法示例。
在下文中一共展示了JSONScanner.getCalendar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cast
import com.alibaba.fastjson.parser.JSONScanner; //导入方法依赖的package包/类
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
Calendar calendar = null;
if (val == null) {
return null;
}
if (val instanceof Date) {
return val;
}
if (val instanceof Number) {
return new Date(((Number) val).longValue());
}
if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
JSONScanner dateLexer = new JSONScanner(strVal);
try {
if (dateLexer.scanISO8601DateIfMatch(false)) {
calendar = dateLexer.getCalendar();
if (clazz == Calendar.class) {
return calendar;
}
val = calendar.getTime();
dateLexer.close();
return val;
}
dateLexer.close();
try {
return parser.getDateFormat().parse(strVal);
} catch (ParseException e) {
return new Date(Long.parseLong(strVal));
}
} finally {
dateLexer.close();
}
} else {
throw new JSONException("parse error");
}
}
示例2: castToLong
import com.alibaba.fastjson.parser.JSONScanner; //导入方法依赖的package包/类
public static final Long castToLong(Object value) {
if (value == null) {
return null;
}
if (value instanceof Number) {
return Long.valueOf(((Number) value).longValue());
}
if (value instanceof String) {
String strVal = (String) value;
if (strVal.length() == 0 || "null".equals(strVal)) {
return null;
}
try {
return Long.valueOf(Long.parseLong(strVal));
} catch (NumberFormatException e) {
JSONScanner dateParser = new JSONScanner(strVal);
Calendar calendar = null;
if (dateParser.scanISO8601DateIfMatch(false)) {
calendar = dateParser.getCalendar();
}
dateParser.close();
if (calendar != null) {
return Long.valueOf(calendar.getTimeInMillis());
}
}
}
throw new JSONException("can not cast to long, value : " + value);
}
示例3: castToLong
import com.alibaba.fastjson.parser.JSONScanner; //导入方法依赖的package包/类
public static final Long castToLong(Object value) {
if (value == null) {
return null;
}
if (value instanceof Number) {
return ((Number) value).longValue();
}
if (value instanceof String) {
String strVal = (String) value;
if (strVal.length() == 0) {
return null;
}
if ("null".equals(strVal) || "NULL".equals(strVal)) {
return null;
}
try {
return Long.parseLong(strVal);
} catch (NumberFormatException ex) {
//
}
JSONScanner dateParser = new JSONScanner(strVal);
Calendar calendar = null;
if (dateParser.scanISO8601DateIfMatch(false)) {
calendar = dateParser.getCalendar();
}
dateParser.close();
if (calendar != null) {
return calendar.getTimeInMillis();
}
}
throw new JSONException("can not cast to long, value : " + value);
}
示例4: castToLong
import com.alibaba.fastjson.parser.JSONScanner; //导入方法依赖的package包/类
public static Long castToLong(Object value){
if(value == null){
return null;
}
if(value instanceof Number){
return ((Number) value).longValue();
}
if(value instanceof String){
String strVal = (String) value;
if(strVal.length() == 0 //
|| "null".equals(strVal) //
|| "NULL".equals(strVal)){
return null;
}
if(strVal.indexOf(',') != 0){
strVal = strVal.replaceAll(",", "");
}
try{
return Long.parseLong(strVal);
} catch(NumberFormatException ex){
//
}
JSONScanner dateParser = new JSONScanner(strVal);
Calendar calendar = null;
if(dateParser.scanISO8601DateIfMatch(false)){
calendar = dateParser.getCalendar();
}
dateParser.close();
if(calendar != null){
return calendar.getTimeInMillis();
}
}
if(value instanceof Map){
Map map = (Map) value;
if(map.size() == 2
&& map.containsKey("andIncrement")
&& map.containsKey("andDecrement")){
Iterator iter = map.values().iterator();
iter.next();
Object value2 = iter.next();
return castToLong(value2);
}
}
throw new JSONException("can not cast to long, value : " + value);
}
示例5: cast
import com.alibaba.fastjson.parser.JSONScanner; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
if (val == null) {
return null;
}
if (val instanceof java.util.Date) {
return (T) val;
} else if (val instanceof Number) {
return (T) new java.util.Date(((Number) val).longValue());
} else if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
JSONScanner dateLexer = new JSONScanner(strVal);
try {
if (dateLexer.scanISO8601DateIfMatch(false)) {
Calendar calendar = dateLexer.getCalendar();
if (clazz == Calendar.class) {
return (T) calendar;
}
return (T) calendar.getTime();
}
} finally {
dateLexer.close();
}
DateFormat dateFormat = parser.getDateFormat();
try {
return (T) dateFormat.parse(strVal);
} catch (ParseException e) {
// skip
}
long longVal = Long.parseLong(strVal);
return (T) new java.util.Date(longVal);
}
throw new JSONException("parse error");
}