mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -18,7 +18,7 @@ public interface Converter {
|
||||
* 如果类型无法确定,将读取默认值的类型做为目标类型
|
||||
*
|
||||
* @param targetType 目标Type,非泛型类使用
|
||||
* @param value 原始值
|
||||
* @param value 原始值,如果对象实现了此接口,则value为this
|
||||
* @return 转换后的值
|
||||
* @throws ConvertException 转换无法正常完成或转换异常时抛出此异常
|
||||
*/
|
||||
|
@@ -30,6 +30,9 @@ import java.util.Map;
|
||||
public class BeanConverter implements Converter, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 单例对象
|
||||
*/
|
||||
public static BeanConverter INSTANCE = new BeanConverter();
|
||||
|
||||
private final CopyOptions copyOptions;
|
||||
@@ -51,7 +54,7 @@ public class BeanConverter implements Converter, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(Type targetType, Object value) throws ConvertException {
|
||||
public Object convert(final Type targetType, final Object value) throws ConvertException {
|
||||
Assert.notNull(targetType);
|
||||
if (null == value) {
|
||||
return null;
|
||||
@@ -62,7 +65,7 @@ public class BeanConverter implements Converter, Serializable {
|
||||
return ((Converter) value).convert(targetType, value);
|
||||
}
|
||||
|
||||
Class<?> targetClass = TypeUtil.getClass(targetType);
|
||||
final Class<?> targetClass = TypeUtil.getClass(targetType);
|
||||
Assert.notNull(targetClass, "Target type is not a class!");
|
||||
|
||||
return convertInternal(targetType, targetClass, value);
|
||||
|
@@ -17,6 +17,9 @@ import java.util.Calendar;
|
||||
public class DateConverter extends AbstractConverter {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 单例
|
||||
*/
|
||||
public static final DateConverter INSTANCE = new DateConverter();
|
||||
|
||||
/**
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.hutool.core.lang.getter;
|
||||
|
||||
import cn.hutool.core.convert.CompositeConverter;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.convert.Converter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
@@ -89,7 +91,21 @@ public interface TypeGetter<K> {
|
||||
* @return 结果值
|
||||
*/
|
||||
default <T> T get(final K key, final Type type, final T defaultValue) {
|
||||
return Convert.convert(type, getObj(key), defaultValue);
|
||||
return get(key, type, CompositeConverter.getInstance(), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型的值,默认自动转换值类型
|
||||
*
|
||||
* @param <T> 目标类型
|
||||
* @param key 键
|
||||
* @param type 目标类型
|
||||
* @param converter 自定义转换器
|
||||
* @param defaultValue 默认值
|
||||
* @return 结果值
|
||||
*/
|
||||
default <T> T get(final K key, final Type type, final Converter converter, final T defaultValue) {
|
||||
return converter.convert(type, getObj(key), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user