mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix mao
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.hutool.core.convert;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
@@ -49,7 +50,7 @@ public abstract class AbstractConverter<T> implements Converter<T>, Serializable
|
||||
if (null == value) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
if (null == defaultValue || targetType.isInstance(defaultValue)) {
|
||||
if (targetType.isInstance(value) && false == Map.class.isAssignableFrom(targetType)) {
|
||||
// 除Map外,已经是目标类型,不需要转换(Map类型涉及参数类型,需要单独转换)
|
||||
|
@@ -1,9 +1,5 @@
|
||||
package cn.hutool.core.convert.impl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.AbstractConverter;
|
||||
import cn.hutool.core.convert.ConverterRegistry;
|
||||
@@ -11,6 +7,10 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.TypeUtil;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* {@link Map} 转换器
|
||||
*
|
||||
@@ -52,7 +52,7 @@ public class MapConverter extends AbstractConverter<Map<?, ?>> {
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Map<?, ?> convertInternal(Object value) {
|
||||
final Map map;
|
||||
Map map;
|
||||
if (value instanceof Map) {
|
||||
final Type[] typeArguments = TypeUtil.getTypeArguments(value.getClass());
|
||||
if (null != typeArguments //
|
||||
@@ -66,6 +66,8 @@ public class MapConverter extends AbstractConverter<Map<?, ?>> {
|
||||
convertMapToMap((Map) value, map);
|
||||
} else if (BeanUtil.isBean(value.getClass())) {
|
||||
map = BeanUtil.beanToMap(value);
|
||||
// 二次转换,转换键值类型
|
||||
map = convertInternal(map);
|
||||
} else {
|
||||
throw new UnsupportedOperationException(StrUtil.format("Unsupport toMap value type: {}", value.getClass().getName()));
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ public class MapUtil {
|
||||
* @return HashMap对象
|
||||
*/
|
||||
public static <K, V> HashMap<K, V> newHashMap() {
|
||||
return new HashMap<K, V>();
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,7 +400,7 @@ public class MapUtil {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
boolean isEnd = true;// 是否结束。标准是元素列表已耗尽
|
||||
boolean isEnd;// 是否结束。标准是元素列表已耗尽
|
||||
int index = 0;// 值索引
|
||||
Map<K, V> map;
|
||||
do {
|
||||
@@ -736,7 +736,7 @@ public class MapUtil {
|
||||
* @since 4.5.4
|
||||
*/
|
||||
public static <K, V> MapWrapper<K, V> wrap(Map<K, V> map) {
|
||||
return new MapWrapper<K, V>(map);
|
||||
return new MapWrapper<>(map);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------- builder
|
||||
|
Reference in New Issue
Block a user