This commit is contained in:
Looly 2022-05-20 12:07:27 +08:00
parent 3f8699f7e9
commit 3ebd7d9ce0
7 changed files with 37 additions and 2 deletions

View File

@ -3,12 +3,15 @@
-------------------------------------------------------------------------------------------------------------
# 5.8.2.M1 (2022-05-18)
# 5.8.2.M1 (2022-05-20)
### 🐣新特性
* 【core 】 BeanUtil拷贝对象增加空检查issue#I58CJ3@Gitee
### 🐞Bug修复
* 【extra 】 修复SshjSftp初始化未能代入端口配置问题issue#2333@Github
* 【core 】 修复Convert.numberToSimple转换问题issue#2334@Github
* 【core 】 修复TemporalAccessorConverter导致的转换问题issue#2341@Github
* 【core 】 修复TemporalAccessorConverter导致的转换问题issue#2341@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -728,6 +728,9 @@ public class BeanUtil {
* @return 目标对象
*/
public static <T> T copyProperties(Object source, Class<T> tClass, String... ignoreProperties) {
if(null == source){
return null;
}
T target = ReflectUtil.newInstanceIfPossible(tClass);
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
return target;
@ -765,6 +768,9 @@ public class BeanUtil {
* @param copyOptions 拷贝选项 {@link CopyOptions}
*/
public static void copyProperties(Object source, Object target, CopyOptions copyOptions) {
if(null == source){
return;
}
BeanCopier.create(source, target, ObjectUtil.defaultIfNull(copyOptions, CopyOptions::create)).copy();
}

View File

@ -1,5 +1,6 @@
package cn.hutool.core.bean.copier;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.copier.Copier;
import java.io.Serializable;
@ -62,6 +63,8 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
* @param copyOptions 拷贝属性选项
*/
public BeanCopier(Object source, T target, Type targetType, CopyOptions copyOptions) {
Assert.notNull(source, "Source bean must be not null!");
Assert.notNull(target, "Target bean must be not null!");
Copier<T> copier;
if (source instanceof Map) {
if (target instanceof Map) {

View File

@ -84,6 +84,12 @@ public class TemporalAccessorConverter extends AbstractConverter<TemporalAccesso
this.format = format;
}
@SuppressWarnings("unchecked")
@Override
public Class<TemporalAccessor> getTargetType() {
return (Class<TemporalAccessor>) this.targetType;
}
@Override
protected TemporalAccessor convertInternal(Object value) {
if (value instanceof Long) {

View File

@ -567,6 +567,11 @@ public class BeanUtilTest {
Assert.assertNull(newFood.getCode());
}
@Test
public void copyNullTest() {
Assert.assertNull(BeanUtil.copyProperties(null, Food.class));
}
@Test
public void copyBeanPropertiesFilterTest() {
Food info = new Food();

View File

@ -15,6 +15,8 @@ import org.junit.Test;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -383,4 +385,11 @@ public class ConvertTest {
float b = Convert.toFloat(a);
Assert.assertEquals(a, b, 5);
}
@Test
public void localDateTimeToLocalDateTest(){
final LocalDateTime localDateTime = LocalDateTime.now();
final LocalDate convert = Convert.convert(LocalDate.class, localDateTime);
Assert.assertEquals(localDateTime.toLocalDate(), convert);
}
}

View File

@ -439,6 +439,9 @@ public class NumberUtilTest {
Assert.assertFalse(NumberUtil.isEven(a[4]));
}
@Test
public void divIntegerTest(){
Assert.assertEquals(1001013, NumberUtil.div(100101300, (Number) 100).intValue());
}
}