mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-05 13:17:58 +08:00
fix BeanDesc bug
This commit is contained in:
parent
91047d1f88
commit
32797d2d14
@ -17,6 +17,7 @@
|
||||
* 【core 】 修复RobotUtil双击右键问题(pr#1721@Github)
|
||||
* 【core 】 修复FileTypeUtil判断wps修改过的xlsx误判为jar的问题(pr#380@Gitee)
|
||||
* 【core 】 修复Sftp.isDir异常bug(pr#378@Gitee)
|
||||
* 【core 】 修复BeanUtil.copyProperties集合元素复制成功,读取失败的问题(issue#I41WKP@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user