JSON库很常用了,现在开源的JSON库也有很多。但是我们仍然面临下列问题
1)时不时的爆出这个Json库出现漏洞,那个json库出现漏洞。一旦出现漏洞只能升级,想切换JSON都不成。
2)一个项目中有多个JSON库(这个原因很多,但又不可避免),改Bug可能都得学习多种JSON库
鉴于如上问题,开发了一套easyjson库,你可以把它看做是slf4j一样,它本身不做JSON的处理,可用它来讲任何的JSON进行适配到其他的JSON库上。
它是基于此思路开发出来的。使用它,你的现有项目不需要做一行的代码改变即可在各个JSON库自如的切换。
仓库地址:Github EasyJSON
关键特性:
目前支持将JSON库适配给fastjson, gson, jackason
| easyjson facade | JSON Implementation |
|---|---|
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>easyjson-core</artifactId>
<version>${version}/version>
</dependency>
|
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>easyjson-gson</artifactId>
<version>${version}/version>
</dependency>
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>easyjson-jackson</artifactId>
<version>${version}/version>
</dependency>
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>easyjson-fastjson</artifactId>
<version>${version}/version>
</dependency>
|
同时也支持将这些JSON通过easyjson 适配:
| JSON Library | Maven | version | Adapter |
|---|---|---|---|
| Android json |
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
</dependency>
|
0.0.20131108.vaadin |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>android-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| fastjson |
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
|
1.2.58 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>fastjson-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| json-lib |
<dependency>
<groupId>com.hynnet</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
</dependency>
|
2.4 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>jsonlib-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| json-smart |
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
</dependency>
|
2.3 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>jsonsmart-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| Eclipse minimal-json |
<dependency>
<groupId>com.eclipsesource.minimal-json</groupId>
<artifactId>minimal-json</artifactId>
<version>0.9.5</version>
</dependency>
|
0.9.5 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>minimaljson-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| org.json |
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
|
20180813 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>orgjson-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| Progsbase JSON |
<dependency>
<groupId>com.progsbase.libraries</groupId>
<artifactId>JSON</artifactId>
<version>0.3.9</version>
</dependency>
|
0.3.9 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>progsbase-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
| json-simple |
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
|
1.1.1 |
<dependency>
<groupId>com.github.fangjinuo.easyjson</groupId>
<artifactId>simplejson-to-easyjson</artifactId>
<version>${version}</version>
</dependency>
|
原文:https://www.cnblogs.com/f1194361820/p/11572138.html