mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -98,20 +98,22 @@ public class CompositeConverter extends RegisterConverter {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convert(Type type, final Object value, final T defaultValue, final boolean isCustomFirst) throws ConvertException {
|
||||
if (TypeUtil.isUnknown(type) && null == defaultValue) {
|
||||
// 对于用户不指定目标类型的情况,返回原值
|
||||
return (T) value;
|
||||
}
|
||||
if (ObjUtil.isNull(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (TypeUtil.isUnknown(type)) {
|
||||
// 对于用户不指定目标类型的情况,返回原值
|
||||
if(null == defaultValue){
|
||||
throw new ConvertException("Unsupported convert to unKnow type: {}", type);
|
||||
return (T) value;
|
||||
}
|
||||
type = defaultValue.getClass();
|
||||
}
|
||||
|
||||
// value本身实现了Converter接口,直接调用
|
||||
if(value instanceof Converter){
|
||||
return ((Converter) value).convert(type, value, defaultValue);
|
||||
}
|
||||
|
||||
if (type instanceof TypeReference) {
|
||||
type = ((TypeReference<?>) type).getType();
|
||||
}
|
||||
|
@@ -57,6 +57,11 @@ public class BeanConverter implements Converter, Serializable {
|
||||
return null;
|
||||
}
|
||||
|
||||
// value本身实现了Converter接口,直接调用
|
||||
if(value instanceof Converter){
|
||||
return ((Converter) value).convert(targetType, value);
|
||||
}
|
||||
|
||||
Class<?> targetClass = TypeUtil.getClass(targetType);
|
||||
Assert.notNull(targetClass, "Target type is not a class!");
|
||||
|
||||
@@ -79,6 +84,6 @@ public class BeanConverter implements Converter, Serializable {
|
||||
return SerializeUtil.deserialize((byte[]) value);
|
||||
}
|
||||
|
||||
throw new ConvertException("Unsupported source type: {}", value.getClass());
|
||||
throw new ConvertException("Unsupported source type: [{}] to [{}]", value.getClass(), targetType);
|
||||
}
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public class DateConverter extends AbstractConverter {
|
||||
return wrap(targetClass, DateUtil.date((TemporalAccessor) value));
|
||||
} else if (value instanceof Calendar) {
|
||||
return wrap(targetClass, DateUtil.date((Calendar) value));
|
||||
} else if (value instanceof Number) {
|
||||
} else if (null == this.format && value instanceof Number) {
|
||||
return wrap(targetClass, ((Number) value).longValue());
|
||||
} else {
|
||||
// 统一按照字符串处理
|
||||
|
Reference in New Issue
Block a user