Merge pull request #1175 from xyz327/v5-dev

FIX:#1173 修复子类使用同名属性覆盖了父类的transient属性导致属性transient检测而被忽略
This commit is contained in:
Golden Looly
2020-10-21 12:59:48 +08:00
committed by GitHub
2 changed files with 35 additions and 2 deletions

View File

@@ -364,12 +364,26 @@ public class BeanUtilTest {
@Getter
@Setter
public static class Person {
public static class SubPersonWithOverlayTransientField extends PersonWithTransientField {
// 覆盖父类中 transient 属性
private String name;
}
@Getter
@Setter
public static class Person {
private String name;
private int age;
private String openid;
}
@Getter
@Setter
public static class PersonWithTransientField {
private transient String name;
private int age;
private String openid;
}
public static class Person2 {
public Person2(String name, int age, String openid) {
@@ -383,6 +397,23 @@ public class BeanUtilTest {
public String openid;
}
/**
* <a href="https://github.com/looly/hutool/issues/1173">#1173</a>
*/
@Test
public void beanToBeanOverlayFieldTest() {
SubPersonWithOverlayTransientField source = new SubPersonWithOverlayTransientField();
source.setName("zhangsan");
source.setAge(20);
source.setOpenid("1");
SubPersonWithOverlayTransientField dest = new SubPersonWithOverlayTransientField();
BeanUtil.copyProperties(source, dest);
Assert.assertEquals(source.getName(), dest.getName());
Assert.assertEquals(source.getAge(), dest.getAge());
Assert.assertEquals(source.getOpenid(), dest.getOpenid());
}
@Test
public void beanToBeanTest() {
// 修复对象无getter方法导致报错的问题