mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复Convert#toMap默认转成HashMap的问题
This commit is contained in:
parent
d4d8522cd4
commit
52dec0c301
@ -43,6 +43,7 @@
|
|||||||
* 【core 】 修复UrlBuilder无法配置末尾追加“/”问题(issue#2459@Github)
|
* 【core 】 修复UrlBuilder无法配置末尾追加“/”问题(issue#2459@Github)
|
||||||
* 【core 】 修复SystemPropsUtil.getBoolean方法应该只有值为true时才返回true,其他情况都应该返回false(pr#717@Gitee)
|
* 【core 】 修复SystemPropsUtil.getBoolean方法应该只有值为true时才返回true,其他情况都应该返回false(pr#717@Gitee)
|
||||||
* 【core 】 修复isBase64判断不准确的问题(pr#727@Gitee)
|
* 【core 】 修复isBase64判断不准确的问题(pr#727@Gitee)
|
||||||
|
* 【core 】 修复Convert#toMap默认转成HashMap的问题(pr#729@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* 类型转换器
|
* 类型转换器
|
||||||
*
|
*
|
||||||
* @author xiaoleilu
|
* @author xiaoleilu
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Convert {
|
public class Convert {
|
||||||
|
|
||||||
@ -614,7 +613,7 @@ public class Convert {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <K, V> Map<K, V> toMap(Class<K> keyType, Class<V> valueType, Object value) {
|
public static <K, V> Map<K, V> toMap(Class<K> keyType, Class<V> valueType, Object value) {
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
return toMap((Class<? extends Map>) value.getClass(), keyType, valueType, value);
|
return toMap((Class<? extends Map<?, ?>>) value.getClass(), keyType, valueType, value);
|
||||||
} else {
|
} else {
|
||||||
return toMap(HashMap.class, keyType, valueType, value);
|
return toMap(HashMap.class, keyType, valueType, value);
|
||||||
}
|
}
|
||||||
@ -631,7 +630,7 @@ public class Convert {
|
|||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @return {@link Map}
|
* @return {@link Map}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public static <K, V> Map<K, V> toMap(Class<? extends Map> mapType, Class<K> keyType, Class<V> valueType, Object value) {
|
public static <K, V> Map<K, V> toMap(Class<? extends Map> mapType, Class<K> keyType, Class<V> valueType, Object value) {
|
||||||
return (Map<K, V>) new MapConverter(mapType, keyType, valueType).convert(value, null);
|
return (Map<K, V>) new MapConverter(mapType, keyType, valueType).convert(value, null);
|
||||||
}
|
}
|
||||||
@ -643,8 +642,8 @@ public class Convert {
|
|||||||
* @param className 类的字符串表示
|
* @param className 类的字符串表示
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @since 4.0.7
|
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
|
* @since 4.0.7
|
||||||
*/
|
*/
|
||||||
public static <T> T convertByClassName(String className, Object value) throws ConvertException {
|
public static <T> T convertByClassName(String className, Object value) throws ConvertException {
|
||||||
return convert(ClassUtil.loadClass(className), value);
|
return convert(ClassUtil.loadClass(className), value);
|
||||||
@ -657,8 +656,8 @@ public class Convert {
|
|||||||
* @param type 类型
|
* @param type 类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @since 4.0.0
|
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public static <T> T convert(Class<T> type, Object value) throws ConvertException {
|
public static <T> T convert(Class<T> type, Object value) throws ConvertException {
|
||||||
return convert((Type) type, value);
|
return convert((Type) type, value);
|
||||||
@ -773,6 +772,7 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- 全角半角转换
|
// ----------------------------------------------------------------------- 全角半角转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 半角转全角,{@code null}返回{@code null}
|
* 半角转全角,{@code null}返回{@code null}
|
||||||
*
|
*
|
||||||
@ -850,6 +850,7 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------- hex
|
// --------------------------------------------------------------------- hex
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串转换成十六进制字符串,结果为小写
|
* 字符串转换成十六进制字符串,结果为小写
|
||||||
*
|
*
|
||||||
@ -952,13 +953,14 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------- 原始包装类型转换
|
// --------------------------------------------------------------- 原始包装类型转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原始类转为包装类,非原始类返回原类
|
* 原始类转为包装类,非原始类返回原类
|
||||||
*
|
*
|
||||||
* @see BasicType#wrap(Class)
|
|
||||||
* @param clazz 原始类
|
* @param clazz 原始类
|
||||||
* @return 包装类
|
* @return 包装类
|
||||||
* @see BasicType#wrap(Class)
|
* @see BasicType#wrap(Class)
|
||||||
|
* @see BasicType#wrap(Class)
|
||||||
*/
|
*/
|
||||||
public static Class<?> wrap(Class<?> clazz) {
|
public static Class<?> wrap(Class<?> clazz) {
|
||||||
return BasicType.wrap(clazz);
|
return BasicType.wrap(clazz);
|
||||||
@ -967,16 +969,17 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 包装类转为原始类,非包装类返回原类
|
* 包装类转为原始类,非包装类返回原类
|
||||||
*
|
*
|
||||||
* @see BasicType#unWrap(Class)
|
|
||||||
* @param clazz 包装类
|
* @param clazz 包装类
|
||||||
* @return 原始类
|
* @return 原始类
|
||||||
* @see BasicType#unWrap(Class)
|
* @see BasicType#unWrap(Class)
|
||||||
|
* @see BasicType#unWrap(Class)
|
||||||
*/
|
*/
|
||||||
public static Class<?> unWrap(Class<?> clazz) {
|
public static Class<?> unWrap(Class<?> clazz) {
|
||||||
return BasicType.unWrap(clazz);
|
return BasicType.unWrap(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- 数字和英文转换
|
// -------------------------------------------------------------------------- 数字和英文转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将阿拉伯数字转为英文表达方式
|
* 将阿拉伯数字转为英文表达方式
|
||||||
*
|
*
|
||||||
@ -1045,8 +1048,7 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 中文大写数字金额转换为数字,返回结果以元为单位的BigDecimal类型数字
|
* 中文大写数字金额转换为数字,返回结果以元为单位的BigDecimal类型数字<br>
|
||||||
*
|
|
||||||
* 如:
|
* 如:
|
||||||
* “陆万柒仟伍佰伍拾陆元叁角贰分”返回“67556.32”
|
* “陆万柒仟伍佰伍拾陆元叁角贰分”返回“67556.32”
|
||||||
* “叁角贰分”返回“0.32”
|
* “叁角贰分”返回“0.32”
|
||||||
@ -1060,6 +1062,7 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- 数字转换
|
// -------------------------------------------------------------------------- 数字转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* int转byte
|
* int转byte
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user