mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix BeanDesc bug
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user