如果数据中有这样格式的时间数据,反序列化的时候框架会抛出NumberFormatException。简单看了一下源码好像是里面判断时间的时候有点问题
if ("0000-00-00".equals(strVal)
|| "0000-00-00T00:00:00".equalsIgnoreCase(strVal)
|| "0001-01-01T00:00:00+08:00".equalsIgnoreCase(strVal)) {
return null;
}
int index = strVal.lastIndexOf('|');
if (index > 20) {
String tzStr = strVal.substring(index + 1);
TimeZone timeZone = TimeZone.getTimeZone(tzStr);
if (!"GMT".equals(timeZone.getID())) {
String subStr = strVal.substring(0, index);
JSONScanner dateLexer = new JSONScanner(subStr);
try {
if (dateLexer.scanISO8601DateIfMatch(false)) {
Calendar calendar = dateLexer.getCalendar();
calendar.setTimeZone(timeZone);
if (clazz == Calendar.class) {
return (T) calendar;
}
return (T) calendar.getTime();
}
} finally {
dateLexer.close();
}
}
}
// 2017-08-14 19:05:30.000|America/Los_Angeles
//
long longVal = Long.parseLong(strVal);
return (T) new java.util.Date(longVal);
判断没有包含这种 0001-01-01T00:00:00
格式的特殊时间数据类型
3条答案
按热度按时间b1uwtaje1#
1.2.60 未复现。
hgtggwj02#
现在发现还有下面这种格式的时间也无法被正确解析,使用的版本是1.2.61
btqmn9zl3#
由于我们项目里面存在和.net接口交互,并且.net项目使用的JSON.Net序列化数据,时间格式默认使用的默认格式。Java项目使用fastjson在解析这种接口返回的时间数据的时候也会出现类似的异常