fix BeanDesc bug

This commit is contained in:
Looly 2021-07-23 22:44:49 +08:00
parent 91047d1f88
commit 32797d2d14
3 changed files with 26 additions and 5 deletions

View File

@ -17,6 +17,7 @@
* 【core 】 修复RobotUtil双击右键问题pr#1721@Github
* 【core 】 修复FileTypeUtil判断wps修改过的xlsx误判为jar的问题pr#380@Gitee
* 【core 】 修复Sftp.isDir异常bugpr#378@Gitee
* 【core 】 修复BeanUtil.copyProperties集合元素复制成功读取失败的问题issue#I41WKP@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -180,11 +180,10 @@ public class PropDesc {
}
if (null != result && null != targetType) {
// 尝试将结果转换为目标类型如果转换失败返回原类型
final Object convertValue = Convert.convertWithCheck(targetType, result, null, ignoreError);
if (null != convertValue) {
result = convertValue;
}
// 尝试将结果转换为目标类型如果转换失败返回null即跳过此属性值
// 来自issues#I41WKP@Gitee当忽略错误情况下目标类型转换失败应返回null
// 如果返回原值在集合注入时会成功但是集合取值时会报类型转换错误
return Convert.convertWithCheck(targetType, result, null, ignoreError);
}
return result;
}

View File

@ -12,6 +12,7 @@ import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.junit.Assert;
import org.junit.Test;
@ -679,4 +680,24 @@ public class BeanUtilTest {
String childMotherName;
String childFatherName;
}
@Test
public void issueI41WKPTest(){
Test1 t1 = new Test1().setStrList(ListUtil.toList("list"));
Test2 t2_hu = new Test2();
BeanUtil.copyProperties(t1, t2_hu, CopyOptions.create().setIgnoreError(true));
Assert.assertNull(t2_hu.getStrList());
}
@Data
@Accessors(chain = true)
public static class Test1 {
private List<String> strList;
}
@Data
@Accessors(chain = true)
public static class Test2 {
private List<Integer> strList;
}
}