mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -4,10 +4,10 @@ import cn.hutool.core.bean.copier.ValueProvider;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Editor;
|
||||
import cn.hutool.core.map.FuncKeyMap;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class MapValueProvider implements ValueProvider<String> {
|
||||
public MapValueProvider(Map map, boolean ignoreCase, boolean ignoreError, Editor<String> keyEditor) {
|
||||
// issue#2202@Github
|
||||
// 如果用户定义了键编辑器,则提供的map中的数据必须全部转换key
|
||||
this.map = new FuncKeyMap(new HashMap(map.size(), 1), (key)->{
|
||||
this.map = new FuncKeyMap(ObjectUtil.clone(map), (key)->{
|
||||
if(ignoreCase && key instanceof CharSequence){
|
||||
key = key.toString().toLowerCase();
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public class MapValueProvider implements ValueProvider<String> {
|
||||
}
|
||||
return key;
|
||||
});
|
||||
this.map.clear();
|
||||
this.map.putAll(map);
|
||||
|
||||
this.ignoreError = ignoreError;
|
||||
|
@@ -55,13 +55,16 @@ public class MapConverter extends AbstractConverter<Map<?, ?>> {
|
||||
protected Map<?, ?> convertInternal(Object value) {
|
||||
Map map;
|
||||
if (value instanceof Map) {
|
||||
final Type[] typeArguments = TypeUtil.getTypeArguments(value.getClass());
|
||||
if (null != typeArguments //
|
||||
&& 2 == typeArguments.length//
|
||||
&& Objects.equals(this.keyType, typeArguments[0]) //
|
||||
&& Objects.equals(this.valueType, typeArguments[1])) {
|
||||
//对于键值对类型一致的Map对象,不再做转换,直接返回原对象
|
||||
return (Map) value;
|
||||
final Class<?> valueClass = value.getClass();
|
||||
if(valueClass.equals(this.mapType)){
|
||||
final Type[] typeArguments = TypeUtil.getTypeArguments(valueClass);
|
||||
if (null != typeArguments //
|
||||
&& 2 == typeArguments.length//
|
||||
&& Objects.equals(this.keyType, typeArguments[0]) //
|
||||
&& Objects.equals(this.valueType, typeArguments[1])) {
|
||||
//对于键值对类型一致的Map对象,不再做转换,直接返回原对象
|
||||
return (Map) value;
|
||||
}
|
||||
}
|
||||
map = MapUtil.createMap(TypeUtil.getClass(this.mapType));
|
||||
convertMapToMap((Map) value, map);
|
||||
|
Reference in New Issue
Block a user