Over a million developers have joined DZone.

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

See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business, brought to you in partnership with AppDynamics.

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.

The Performance Zone is brought to you in partnership with AppDynamics.  See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}