修复isXXX转换时的匹配问题

This commit is contained in:
Looly 2023-02-22 19:33:56 +08:00
parent fb3ea9a3cf
commit fe7751342e
4 changed files with 26 additions and 15 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.8.13.M1 (2023-02-21)
# 5.8.13.M1 (2023-02-22)
### 🐣新特性
### 🐞Bug修复
@ -15,6 +15,7 @@
* 【core 】 修复ReUtil.delAll方法当 content 仅为空格时的问题issue#I6GIMT@Gitee
* 【core 】 修复Tailer文件内容跟随在调用stop后文件依旧被占用问题issue#I6GFD2@Gitee
* 【core 】 修复ReflectUtil.invokeRaw方法中参数类型转换动作未生效的问题pr#2912@Github
* 【core 】 修复isXXX转换时的匹配问题issue#I6H0XF@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -114,17 +114,6 @@ public class MapToBeanCopier<T> extends AbsCopier<Map<?, ?>, T> {
// 转驼峰尝试查找
sKeyStr = StrUtil.toCamelCase(sKeyStr);
propDesc = targetPropDescMap.get(sKeyStr);
if(null != propDesc){
return propDesc;
}
// boolean类型参数名转换尝试查找
if(sKeyStr.startsWith("is")){
sKeyStr = StrUtil.removePreAndLowerFirst(sKeyStr, 2);
propDesc = targetPropDescMap.get(sKeyStr);
return propDesc;
}
return null;
return propDesc;
}
}

View File

@ -248,8 +248,10 @@ public class BeanUtilTest {
final SubPersonWithAlias subPersonWithAlias = BeanUtil.toBean(map, SubPersonWithAlias.class);
Assert.assertEquals("sub名字", subPersonWithAlias.getSubName());
Assert.assertTrue(subPersonWithAlias.isBooleana());
Assert.assertEquals(true, subPersonWithAlias.getBooleanb());
//https://gitee.com/dromara/hutool/issues/I6H0XF
Assert.assertFalse(subPersonWithAlias.isBooleana());
Assert.assertNull(subPersonWithAlias.getBooleanb());
}
@Test

View File

@ -0,0 +1,19 @@
package cn.hutool.json;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
public class IssueI6H0XFTest {
@Test
public void toBeanTest(){
final Demo demo = JSONUtil.toBean("{\"biz\":\"A\",\"isBiz\":true}", Demo.class);
Assert.assertEquals("A", demo.getBiz());
Assert.assertEquals("{\"biz\":\"A\"}", JSONUtil.toJsonStr(demo));
}
@Data
static class Demo {
String biz;
}
}