mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
cd53378ae3
commit
2c060433b9
@ -22,6 +22,7 @@ import org.dromara.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -181,6 +182,11 @@ public class CompositeConverter extends RegisterConverter {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 日期、java.sql中的日期以及自定义日期统一处理
|
||||
if(Date.class.isAssignableFrom(rowType)){
|
||||
return DateConverter.INSTANCE.convert(type, value, defaultValue);
|
||||
}
|
||||
|
||||
// 集合转换(含有泛型参数,不可以默认强转)
|
||||
if (Collection.class.isAssignableFrom(rowType)) {
|
||||
return (T) CollectionConverter.INSTANCE.convert(type, value, (Collection<?>) defaultValue);
|
||||
|
@ -176,13 +176,6 @@ public class RegisterConverter implements Converter, Serializable {
|
||||
// 日期时间
|
||||
defaultConverterMap.put(Calendar.class, new CalendarConverter());
|
||||
defaultConverterMap.put(XMLGregorianCalendar.class, new XMLGregorianCalendarConverter());
|
||||
defaultConverterMap.put(java.util.Date.class, DateConverter.INSTANCE);
|
||||
defaultConverterMap.put(DateTime.class, DateConverter.INSTANCE);
|
||||
|
||||
// 日期时间 java.sql
|
||||
defaultConverterMap.put(java.sql.Date.class, DateConverter.INSTANCE);
|
||||
defaultConverterMap.put(java.sql.Time.class, DateConverter.INSTANCE);
|
||||
defaultConverterMap.put(java.sql.Timestamp.class, DateConverter.INSTANCE);
|
||||
|
||||
// 日期时间 JDK8+(since 5.0.0)
|
||||
defaultConverterMap.put(TemporalAccessor.class, TemporalAccessorConverter.INSTANCE);
|
||||
|
@ -16,7 +16,6 @@ import org.dromara.hutool.core.convert.AbstractConverter;
|
||||
import org.dromara.hutool.core.convert.ConvertException;
|
||||
import org.dromara.hutool.core.date.DateTime;
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.dromara.hutool.core.date.SqlDateUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
@ -113,17 +112,8 @@ public class DateConverter extends AbstractConverter {
|
||||
if (DateTime.class == targetClass) {
|
||||
return date;
|
||||
}
|
||||
if (java.sql.Date.class == targetClass) {
|
||||
return SqlDateUtil.date(date);
|
||||
}
|
||||
if (java.sql.Time.class == targetClass) {
|
||||
return SqlDateUtil.time(date);
|
||||
}
|
||||
if (java.sql.Timestamp.class == targetClass) {
|
||||
return SqlDateUtil.timestamp(date);
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException(StrUtil.format("Unsupported target Date type: {}", targetClass.getName()));
|
||||
return wrap(targetClass, date.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -255,7 +255,12 @@ public class MapUtil extends MapGetUtil {
|
||||
public static <K, V> Map<K, V> createMap(final Class<?> mapType, final Supplier<Map<K, V>> defaultMap) {
|
||||
Map<K, V> result = null;
|
||||
if (null != mapType && !mapType.isAssignableFrom(AbstractMap.class)) {
|
||||
result = (Map<K, V>) ConstructorUtil.newInstanceIfPossible(mapType);
|
||||
try{
|
||||
result = (Map<K, V>) ConstructorUtil.newInstanceIfPossible(mapType);
|
||||
} catch (final Exception ignore){
|
||||
// JDK9+抛出java.lang.reflect.InaccessibleObjectException
|
||||
// 跳过
|
||||
}
|
||||
}
|
||||
|
||||
if(null == result){
|
||||
|
@ -255,6 +255,11 @@ public class JSONConverter implements Converter {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 日期、java.sql中的日期以及自定义日期统一处理
|
||||
if(Date.class.isAssignableFrom(rowType)){
|
||||
return (T) DateConverter.INSTANCE.convert(type, value);
|
||||
}
|
||||
|
||||
// 集合转换(含有泛型参数,不可以默认强转)
|
||||
if (Collection.class.isAssignableFrom(rowType)) {
|
||||
return (T) CollectionConverter.INSTANCE.convert(type, value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user