mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-06 21:58:03 +08:00
fix bug
This commit is contained in:
parent
9ecd578896
commit
dff3dfec68
@ -50,6 +50,10 @@ public class MapToMapCopier extends AbsCopier<Map, Map> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sValue = entry.getValue();
|
sValue = entry.getValue();
|
||||||
|
// 忽略空值
|
||||||
|
if (copyOptions.ignoreNullValue && sValue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Object targetValue = target.get(sKey);
|
final Object targetValue = target.get(sKey);
|
||||||
// 非覆盖模式下,如果目标值存在,则跳过
|
// 非覆盖模式下,如果目标值存在,则跳过
|
||||||
|
@ -575,6 +575,21 @@ public class BeanUtilTest {
|
|||||||
Assert.assertNull(BeanUtil.copyProperties(null, Food.class));
|
Assert.assertNull(BeanUtil.copyProperties(null, Food.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void copyPropertiesMapToMapIgnoreNullTest() {
|
||||||
|
// 测试MapToMap
|
||||||
|
final Map<String, Object> p1 = new HashMap<>();
|
||||||
|
p1.put("isSlow", true);
|
||||||
|
p1.put("name", "测试");
|
||||||
|
p1.put("subName", null);
|
||||||
|
|
||||||
|
final Map<String, Object> map = MapUtil.newHashMap();
|
||||||
|
BeanUtil.copyProperties(p1, map, CopyOptions.of().setIgnoreNullValue(true));
|
||||||
|
Assert.assertTrue((Boolean) map.get("isSlow"));
|
||||||
|
Assert.assertEquals("测试", map.get("name"));
|
||||||
|
Assert.assertFalse(map.containsKey("subName"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void copyBeanPropertiesFilterTest() {
|
public void copyBeanPropertiesFilterTest() {
|
||||||
final Food info = new Food();
|
final Food info = new Food();
|
||||||
|
Loading…
Reference in New Issue
Block a user