Over a million developers have joined DZone.

Comparing the JSON APIs Gson and Jackson

DZone's Guide to

Comparing the JSON APIs Gson and Jackson

Compare JSON APIs Gson and Jackson based on performance for JSON conversion wrappers and creation of lists in both APIs.

· Performance Zone ·
Free Resource

Built by operators for operators, the Sensu monitoring event pipeline empowers businesses to automate their monitoring workflows and gain deep visibility into their multi-cloud environments. Get started for free today.

In this post we will compare two famous JSON specific API i.e. Gson and Jackson from a performance point of view:json_1



This class is used for conversion to JSON

public class MeasurementRecord {

private String measurementId;

private long duration;

private long time;

private MeasurementType type=MeasurementType.METHOD_CALL;

 * @param measurementId
 * @param duration
 * @param time
 * @param type
public MeasurementRecord(String measurementId, long duration, long time,
MeasurementType type) {
this.measurementId = measurementId;
this.duration = duration;
this.time = time;
this.type = type;
//getters and setters

public enum MeasurementType {



Code for Creating List

private static List<String> getList(int iteration){
List l=new ArrayList();
for(int i=0;i<iteration;i++){
l.add(new MeasurementRecord("/test.html", 10, System.currentTimeMillis(), MeasurementType.WEB_REQUEST));
return l;

Jackson API

private static long jacksonTest(int iteration)throws Exception{
ObjectMapper mapper=new ObjectMapper();
List<String> l=getList(iteration);
long T1=System.nanoTime();
String json=mapper.writeValueAsString(l);
long T2=System.nanoTime();
return (T2-T1);

Gson API

private static long gsonTest(int iteration){
Gson gson = new GsonBuilder().create();
List l=getList(iteration);
long T1=System.nanoTime();
String json=gson.toJson(l);
long T2=System.nanoTime();
return (T2-T1);




For converting small- or medium-sized lists, Gson provides a better response compared to Jackson. For large lists, Jackson provides a better response than Gson. Based on this results one can conclude that for converting small or medium size list to JSON one can use Gson for better performance.

Download our guide to mitigating alert fatigue, with real-world tips on automating remediation and triage from an IT veteran.

gson ,java ,json ,jackson ,performance

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}