use of cn.hutool.core.convert.ConvertException in project hutool by looly.
the class DateConverter method convertInternal.
@Override
protected java.util.Date convertInternal(Object value) {
if (value == null || (value instanceof CharSequence && StrUtil.isBlank(value.toString()))) {
return null;
}
if (value instanceof TemporalAccessor) {
return wrap(DateUtil.date((TemporalAccessor) value));
} else if (value instanceof Calendar) {
return wrap(DateUtil.date((Calendar) value));
} else if (value instanceof Number) {
return wrap(((Number) value).longValue());
} else {
// 统一按照字符串处理
final String valueStr = convertToStr(value);
final DateTime dateTime = //
StrUtil.isBlank(this.format) ? //
DateUtil.parse(valueStr) : DateUtil.parse(valueStr, this.format);
if (null != dateTime) {
return wrap(dateTime);
}
}
throw new ConvertException("Can not convert {}:[{}] to {}", value.getClass().getName(), value, this.targetType.getName());
}
Aggregations