mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
commit
4123efcad9
@ -292,7 +292,7 @@ public class CopyOptions implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否覆盖目标值,如果不覆盖,会先读取目标对象的值,非{@code null}则写,否则忽略。如果覆盖,则不判断直接写
|
||||
* 设置是否覆盖目标值,如果不覆盖,会先读取目标对象的值,为{@code null}则写,否则忽略。如果覆盖,则不判断直接写
|
||||
*
|
||||
* @param override 是否覆盖目标值
|
||||
* @return this
|
||||
|
@ -55,6 +55,26 @@ public class BeanCopierTest {
|
||||
Assert.assertEquals("123", b.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 为{@code null}则写,否则忽略。如果覆盖,则不判断直接写
|
||||
*/
|
||||
@Test
|
||||
public void issues2484Test() {
|
||||
final A a = new A();
|
||||
a.setValue("abc");
|
||||
final B b = new B();
|
||||
b.setValue("123");
|
||||
|
||||
BeanCopier<B> copier = BeanCopier.create(a, b, CopyOptions.create().setOverride(false));
|
||||
copier.copy();
|
||||
Assert.assertEquals("123", b.getValue());
|
||||
|
||||
b.setValue(null);
|
||||
copier = BeanCopier.create(a, b, CopyOptions.create().setOverride(false));
|
||||
copier.copy();
|
||||
Assert.assertEquals("abc", b.getValue());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class A {
|
||||
private String value;
|
||||
|
Loading…
Reference in New Issue
Block a user