Package com.ultikits.ultitools.utils
Class BeanCopyUtil
java.lang.Object
com.ultikits.ultitools.utils.BeanCopyUtil
Bean copy utility class.
Replaces hutool BeanUtil.copyProperties().
- Since:
- 6.2.0
- Author:
- wisdomme
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ObjectconvertNumber(Number num, Class<?> targetType) private static ObjectconvertValue(Object value, Class<?> targetType) Converts a basic type.private static voidcopyFieldValue(Object source, Object target, Field sourceField, Field targetField, boolean ignoreNullValue) static voidcopyProperties(Object source, Object target) Copies properties.static voidcopyProperties(Object source, Object target, boolean ignoreNullValue) Copies properties.static voidcopyProperties(Object source, Object target, boolean ignoreNullValue, String... ignoreFields) Copies properties.static voidcopyProperties(Object source, Object target, String... ignoreFields) Copies properties, excluding the specified fields.static <T> TcopyToNewInstance(Object source, Class<T> targetClass) Copies to a new instance.private static FieldfindWritableTargetField(Class<?> targetClass, String fieldName) private static booleanisStaticOrFinal(Field field) private static booleanshouldSkipField(Field field, Set<String> ignoreSet)
-
Constructor Details
-
BeanCopyUtil
private BeanCopyUtil()
-
-
Method Details
-
copyProperties
Copies properties.- Parameters:
source- the source objecttarget- the target object
-
copyProperties
Copies properties.- Parameters:
source- the source objecttarget- the target objectignoreNullValue- whether to ignore null values
-
copyProperties
Copies properties, excluding the specified fields.- Parameters:
source- the source objecttarget- the target objectignoreFields- the field names to exclude
-
copyProperties
public static void copyProperties(Object source, Object target, boolean ignoreNullValue, String... ignoreFields) Copies properties.- Parameters:
source- the source objecttarget- the target objectignoreNullValue- whether to ignore null valuesignoreFields- the field names to exclude
-
shouldSkipField
-
isStaticOrFinal
-
findWritableTargetField
-
copyFieldValue
-
copyToNewInstance
Copies to a new instance.- Type Parameters:
T- the target type- Parameters:
source- the source objecttargetClass- the target class- Returns:
- the new instance
-
convertValue
Converts a basic type. -
convertNumber
-