mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -199,7 +199,7 @@ public class BeanUtil {
|
||||
// 先尝试直接获取属性
|
||||
if (bean instanceof Map) {
|
||||
final Map<?, ?> map = (Map<?, ?>) bean;
|
||||
if(map.containsKey(expression)){
|
||||
if (map.containsKey(expression)) {
|
||||
return (T) map.get(expression);
|
||||
}
|
||||
}
|
||||
@@ -309,6 +309,7 @@ public class BeanUtil {
|
||||
|
||||
/**
|
||||
* 将Bean包装为Map形式
|
||||
*
|
||||
* @param bean Bean
|
||||
* @return {@link BeanMap}
|
||||
* @since 6.0.0
|
||||
@@ -391,6 +392,7 @@ public class BeanUtil {
|
||||
* 3. 自定义字段前缀或后缀等等
|
||||
* </pre>
|
||||
*
|
||||
* @param <V> Map中值类型
|
||||
* @param bean bean对象
|
||||
* @param targetMap 目标的Map
|
||||
* @param ignoreNullValue 是否忽略值为空的字段
|
||||
@@ -398,10 +400,10 @@ public class BeanUtil {
|
||||
* @return Map
|
||||
* @since 4.0.5
|
||||
*/
|
||||
public static Map<String, Object> beanToMap(final Object bean,
|
||||
final Map<String, Object> targetMap,
|
||||
final boolean ignoreNullValue,
|
||||
final UnaryOperator<MutableEntry<Object, Object>> keyEditor) {
|
||||
public static <V> Map<String, V> beanToMap(final Object bean,
|
||||
final Map<String, V> targetMap,
|
||||
final boolean ignoreNullValue,
|
||||
final UnaryOperator<MutableEntry<Object, Object>> keyEditor) {
|
||||
if (null == bean) {
|
||||
return null;
|
||||
}
|
||||
@@ -425,13 +427,14 @@ public class BeanUtil {
|
||||
* ...
|
||||
* </pre>
|
||||
*
|
||||
* @param <V> Map中值类型
|
||||
* @param bean bean对象
|
||||
* @param targetMap 目标的Map
|
||||
* @param copyOptions 拷贝选项
|
||||
* @return Map
|
||||
* @since 5.7.15
|
||||
*/
|
||||
public static Map<String, Object> beanToMap(final Object bean, final Map<String, Object> targetMap, final CopyOptions copyOptions) {
|
||||
public static <V> Map<String, V> beanToMap(final Object bean, final Map<String, V> targetMap, final CopyOptions copyOptions) {
|
||||
if (null == bean) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -19,8 +19,10 @@ package org.dromara.hutool.core.convert.impl;
|
||||
import org.dromara.hutool.core.bean.BeanUtil;
|
||||
import org.dromara.hutool.core.convert.ConvertException;
|
||||
import org.dromara.hutool.core.convert.Converter;
|
||||
import org.dromara.hutool.core.convert.ConverterWithRoot;
|
||||
import org.dromara.hutool.core.convert.MatcherConverter;
|
||||
import org.dromara.hutool.core.lang.tuple.Pair;
|
||||
import org.dromara.hutool.core.lang.wrapper.Wrapper;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.core.reflect.ConstructorUtil;
|
||||
import org.dromara.hutool.core.reflect.TypeReference;
|
||||
@@ -43,18 +45,16 @@ import java.util.Map;
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class EntryConverter implements MatcherConverter, Serializable {
|
||||
public class EntryConverter extends ConverterWithRoot implements MatcherConverter, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Converter convert;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param converter 转换器,用于将Entry中key和value转换为指定类型的对象
|
||||
*/
|
||||
public EntryConverter(final Converter converter) {
|
||||
this.convert = converter;
|
||||
super(converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,7 +141,7 @@ public class EntryConverter implements MatcherConverter, Serializable {
|
||||
private Map.Entry<?, ?> mapToEntry(final Type targetType, final Type keyType, final Type valueType, final Map map) {
|
||||
|
||||
final Object key;
|
||||
final Object value;
|
||||
Object value;
|
||||
if (1 == map.size()) {
|
||||
final Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
|
||||
key = entry.getKey();
|
||||
@@ -152,9 +152,13 @@ public class EntryConverter implements MatcherConverter, Serializable {
|
||||
value = map.get("value");
|
||||
}
|
||||
|
||||
if(value instanceof Wrapper){
|
||||
value = ((Wrapper) value).getRaw();
|
||||
}
|
||||
|
||||
return (Map.Entry<?, ?>) ConstructorUtil.newInstance(TypeUtil.getClass(targetType),
|
||||
TypeUtil.isUnknown(keyType) ? key : convert.convert(keyType, key),
|
||||
TypeUtil.isUnknown(valueType) ? value : convert.convert(valueType, value)
|
||||
TypeUtil.isUnknown(keyType) ? key : rootConverter.convert(keyType, key),
|
||||
TypeUtil.isUnknown(valueType) ? value : rootConverter.convert(valueType, value)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -82,8 +82,7 @@ public class MapConverter extends ConverterWithRoot implements MatcherConverter,
|
||||
* @throws ConvertException 转换异常或不支持的类型
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Map<?, ?> convert(final Type targetType, final Type keyType, final Type valueType, final Object value)
|
||||
throws ConvertException{
|
||||
public Map<?, ?> convert(final Type targetType, final Type keyType, final Type valueType, final Object value) throws ConvertException{
|
||||
Map map;
|
||||
if (value instanceof Map) {
|
||||
final Class<?> valueClass = value.getClass();
|
||||
|
Reference in New Issue
Block a user