mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix(hutool-core): 修复子类使用同名属性覆盖了父类的transient属性导致属性transient检测而被忽略
This commit is contained in:
parent
c008d0a081
commit
995bacc253
@ -146,7 +146,9 @@ public class BeanDesc implements Serializable {
|
||||
if (false == ModifierUtil.isStatic(field)) {
|
||||
//只针对非static属性
|
||||
prop = createProp(field, methods);
|
||||
this.propMap.put(prop.getFieldName(), prop);
|
||||
PropDesc finalProp = prop;
|
||||
// 只有不存在时才放入,防止父类属性覆盖子类属性
|
||||
this.propMap.putIfAbsent(prop.getFieldName(), finalProp);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
@ -362,6 +362,13 @@ public class BeanUtilTest {
|
||||
private Boolean slow;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class SubPersonWithOverlayTransientField extends PersonWithTransientField {
|
||||
// 覆盖父类中 transient 属性
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class Person {
|
||||
@ -370,6 +377,13 @@ public class BeanUtilTest {
|
||||
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方法导致报错的问题
|
||||
|
Loading…
x
Reference in New Issue
Block a user