提交 17b735d4 编写于 作者: 勤为径苦作舟's avatar 勤为径苦作舟

feat: BeanUtils 新增 deepClone(深克隆)方法和深克隆性能测试

上级 4920e333
......@@ -130,7 +130,18 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
<version>2.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.4.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.6</version>
</dependency>
......@@ -172,7 +183,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.1</version>
<version>5.8.11</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -193,6 +204,54 @@
<!-- <version>31.1-jre</version>-->
<!-- <scope>test</scope>-->
<!--</dependency>-->
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-serializer-fast2</artifactId>
<version>9.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.66</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>3.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......@@ -385,6 +444,11 @@
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<!-- jitpack -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
......
package top.csaf.bean;
import com.alibaba.fastjson2.JSON;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.PropertyUtils;
......@@ -356,4 +357,30 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
}
return targetList;
}
/**
* 深克隆
*
* @param source 源对象
* @param <T> 源对象类型
* @return 深克隆后的对象
*/
public static <T> T deepClone(T source) {
return (T) JSON.parseObject(JSON.toJSONString(source), source.getClass());
}
/**
* 深克隆
*
* @param source 源集合
* @param <T> 源集合元素类型
* @return 深克隆后的集合
*/
public static <T> List<T> deepClone(List<T> source) {
List<T> result = new ArrayList<>();
for (T t : source) {
result.add(deepClone(t));
}
return result;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册