diff --git a/CHANGELOG.md b/CHANGELOG.md index c393aeb89..e8ded4206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,13 @@ ------------------------------------------------------------------------------------------------------------- -# 5.6.3 (2021-04-02) +# 5.6.3 (2021-04-03) ### 新特性 * 【core 】 修改数字转换的实现,增加按照指定端序转换(pr#1492@Github) * 【core 】 修改拆分byte数组时最后一组长度的规则(pr#1494@Github) * 【core 】 新增根据日期获取节气(pr#1496@Github) +* 【core 】 mapToBean()添加对布尔值is前缀的识别(pr#294@Gitee) ### Bug修复 * 【core 】 修复Validator.isUrl()传空返回true(issue#I3ETTY@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/bean/copier/provider/MapValueProvider.java b/hutool-core/src/main/java/cn/hutool/core/bean/copier/provider/MapValueProvider.java index 284858fe2..7c84e4074 100644 --- a/hutool-core/src/main/java/cn/hutool/core/bean/copier/provider/MapValueProvider.java +++ b/hutool-core/src/main/java/cn/hutool/core/bean/copier/provider/MapValueProvider.java @@ -10,7 +10,14 @@ import java.util.Map; /** * Map值提供者,支持驼峰和下划线的key兼容。
- * 假设目标属性为firstName,则Map中为firstName或first_name都可以对应到值。 + * 假设目标属性为firstName,则Map中以下形式的值都可以对应: + * + * 为firstName或first_name都可以对应到值。 * * @author looly */ @@ -50,17 +57,22 @@ public class MapValueProvider implements ValueProvider { @Override public Object value(String key, Type valueType) { - Object value = map.get(getKey(key, valueType)); + final String key1 = getKey(key, valueType); + if (null == key1) { + return null; + } + + final Object value = map.get(key1); return Convert.convertWithCheck(valueType, value, null, this.ignoreError); } @Override public boolean containsKey(String key) { - return map.containsKey(getKey(key, null)); + return null != getKey(key, null); } /** - * 获得map中可能包含的key + * 获得map中可能包含的key,不包含返回null * * @param key map中可能包含的key * @param valueType 值类型,用于判断是否为Boolean,可以为null @@ -72,27 +84,26 @@ public class MapValueProvider implements ValueProvider { } //检查下划线模式 - String containKey = StrUtil.toUnderlineCase(key); - if (map.containsKey(containKey)) { - return containKey; + String customKey = StrUtil.toUnderlineCase(key); + if (map.containsKey(customKey)) { + return customKey; } //检查boolean类型 if (null == valueType || Boolean.class == valueType || boolean.class == valueType) { //boolean类型字段字段名支持两种方式 - containKey = StrUtil.upperFirstAndAddPre(key, "is"); - if (map.containsKey(containKey)) { - return containKey; + customKey = StrUtil.upperFirstAndAddPre(key, "is"); + if (map.containsKey(customKey)) { + return customKey; } //检查下划线模式 - containKey = StrUtil.toUnderlineCase(containKey); - if (map.containsKey(containKey)) { - return containKey; + customKey = StrUtil.toUnderlineCase(customKey); + if (map.containsKey(customKey)) { + return customKey; } } - - return key; + return null; } }