com.github.houbb:deep-copy-hession

深度拷贝实现整合.

License

License

GroupId

GroupId

com.github.houbb
ArtifactId

ArtifactId

deep-copy-hession
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

深度拷贝实现整合.

Download deep-copy-hession

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.houbb/deep-copy-hession/ -->
<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>deep-copy-hession</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.houbb/deep-copy-hession/
implementation 'com.github.houbb:deep-copy-hession:0.0.1'
// https://jarcasting.com/artifacts/com.github.houbb/deep-copy-hession/
implementation ("com.github.houbb:deep-copy-hession:0.0.1")
'com.github.houbb:deep-copy-hession:jar:0.0.1'
<dependency org="com.github.houbb" name="deep-copy-hession" rev="0.0.1">
  <artifact name="deep-copy-hession" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.houbb', module='deep-copy-hession', version='0.0.1')
)
libraryDependencies += "com.github.houbb" % "deep-copy-hession" % "0.0.1"
[com.github.houbb/deep-copy-hession "0.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
com.github.houbb : deep-copy-api jar 0.0.1
com.caucho : hessian jar 4.0.38

Project Modules

There are no modules declared in this project.

项目介绍

深度拷贝的常见实现整合,便于后期拓展。

Build Status Maven Central Open Source Love

变更日志

特性

  • 基于 FastJson 实现

  • 基于 JackJson 实现

  • 基于 GSON 实现

  • 基于 FST 实现

  • 基于 JsonIter 实现

  • 基于 Hession 实现

快速开始

环境准备

JDK 7+

Maven 3.x

maven 导入

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>deep-copy-all</artifactId>
    <version>0.0.1</version>
</dependency>

工厂类

可以直接通过 DeepCopyFactory 工厂类获取对应的实现,如下:

实现 说明 备注
fastJson() fast json 实现
jackson() jackson 实现
gson() google json 实现
fst() fst 实现 需要实现 Serializable
hession() hession 实现 需要实现 Serializable
jsonIter() json iter 实现

单个模块

默认引入上面的所有实现,当前你可以只引入单独的模块。

maven 坐标中的 artifactId 的 deep-copy-* 如下:

实现 说明
fastjson fast json 模块
jackson jackson 模块
gson google json 模块
fst fst 模块
hession hession 模块
jsoniter json iter 模块

可以自己的需要单独引入,比如只引入 fastjson 依赖:

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>deep-copy-fastjson</artifactId>
    <version>0.0.1</version>
</dependency>

自定义

自定义的方式只需要 2 步:

(1)引入 api 依赖

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>deep-copy-api</artifactId>
    <version>0.0.1</version>
</dependency>

(2)实现对应的接口

实现对应的 IDeepCopy 接口即可,以 FastJson 实现为例:

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.houbb.deep.copy.api.AbstractDeepCopy;

/**
 * FastJson 深度拷贝实现
 * @author binbin.hou
 * @since 0.0.1
 */
public class FastJsonDeepCopy extends AbstractDeepCopy {

    @Override
    @SuppressWarnings("unchecked")
    protected <T> T doDeepCopy(T object) {
        final Class<?> clazz = object.getClass();
        String jsonString = JSON.toJSONString(object, SerializerFeature.DisableCircularReferenceDetect);
        return (T) JSON.parseObject(jsonString, clazz);
    }

}

Benchmark

相同对象,循环 10w 次性能对比图。

deep-copy-benchmark.png

参见 BenchmarkTest

ROAD-MAP

  • 自己实现

Versions

Version
0.0.1