Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

Compare_JSON_API

wenshao edited this page May 15, 2016 · 7 revisions

License & Project URL

 | License | URL

---------|------------|------------------------------------------ Fastjson | Apaceh 2.0 | https://github.com/alibaba/fastjson Gson | Apaceh 2.0 | https://github.com/google/gson Jackson | Apaceh 2.0 | https://github.com/FasterXML/jackson-core

Maven

fastjson

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.11</version>
</dependency>

fastjson-android

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.51.android</version>
</dependency>

jackson

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>

gson

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>

API

Fastjson parse Tree

importcom.alibaba.fastjson.*;
JSONObjectjsonObj = JSON.parseObject(jsonStr);

Fastjson parse POJO

importcom.alibaba.fastjson.JSON;
Modelmodel = JSON.parseObject(jsonStr, Model.class);

Fastjson parse POJO Generic

importcom.alibaba.fastjson.JSON;
Typetype = newTypeReference<List<Model>>() {}.getType(); List<Model> list = JSON.parseObject(jsonStr, type);

Fastjson convert POJO to json string

importcom.alibaba.fastjson.JSON;
Modelmodel = ...; StringjsonStr = JSON.toJSONString(model);

Fastjson convert POJO to json bytes

importcom.alibaba.fastjson.JSON;
Modelmodel = ...; byte[] jsonBytes = JSON.toJSONBytes(model);

Fastjson write POJO as json string to OutputStream

importcom.alibaba.fastjson.JSON;
Modelmodel = ...; OutputStreamos;
JSON.writeJSONString(os, model);

Fastjson write POJO as json string to Writer

importcom.alibaba.fastjson.JSON;
Modelmodel = ...; Writerwriter = ...;
JSON.writeJSONString(writer, model);

Clone this wiki locally