目前版本1.0.3
具备支持生产环境使用能力。
Fastjson-replacement
是一个用于替换Fastjson
实现替换为Jackson
实现的桥接模式工具,这让习惯于Fastjson
用法的开发者或者已经大批量使用Fastjson
的遗留工程代码可以轻松的做出改变,而无需改变现有的使用习惯与人体工程学体验。
- 支持
java.util.Date
,java 8 jsr310 time packages
(LocalDate
,LocalDateTime
,LocalTime
) - 支持多种时间格式反序列化(目前:
yyyy-MM-dd HH:mm:ss
,yyyy-MM-dd
)
为什么要替换fastjson
? 因为其漏洞多,修复速度慢。
为什么重造轮子?测试完备度不够,没有自动发布和及时更新版本。
步骤1:添加依赖
使用默认的jackson
版本(当前1.12.3
)
maven
<dependency>
<groupId>io.github.qingmo</groupId>
<artifactId>fastjson-replacement</artifactId>
<version>1.0.3</version>
</dependency>
gradle
implementation("io.github.qingmo:fastjson-replacement:1.0.3")
使用自定义版本的jackson
版本
maven
<dependency>
<groupId>io.github.qingmo</groupId>
<artifactId>fastjson-replacement</artifactId>
<version>1.0.3</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
</exclusion>
</exclusions>
</dependency>
gradle
implementation("io.github.qingmo:fastjson-replacement:1.0.3") {
exclude(group = "com.fasterxml.jackson.core")
exclude(group = "com.fasterxml.jackson")
}
步骤2:替换fastjson的包
替换方法
import com.alibaba.fastjson.JSON
替换为
import io.github.qingmo.json.JSON
import com.alibaba.fastjson.JSONArray
替换为
import io.github.qingmo.json.JSONArray
import com.alibaba.fastjson.JSONObject
替换为
import io.github.qingmo.json.JSONObject
-
可靠性
这个系统或库必须正确的工作。
Fastjson-replacement
提供了100%的代码覆盖率来保障。 -
性能
这个系统或库必须在一个可预期的性能表现。
如果这个库是目前问题的唯一解决方案,那么性能表现应该在可容忍的范围内;
如果这个库是目前问题的另外一个可选解决方案,那么它的性能表现应该等于或优于目前的解决方案性能平均水平。
Fastjson-replacement
的性能测试成绩如下(基于 json-comparsion):
-
不支持
kotin data class
kotlin data class
需要jackson-module-kotlin
,这个模块目前是基于kotlin反射,其在反序列化过程中性能表现极差。 我在等待新的一个PR合并 FasterXML/jackson-module-kotlin#439