FastJson: Performance, Popularity, and Issues – A Comparative Study with Jackson and Gson
This article examines Alibaba's FastJson library, comparing its parsing speed and popularity against Jackson and Gson, presents benchmark results, highlights code defects and unresolved issues, and concludes with recommendations for using Jackson over FastJson in Java backend projects.
1. What is FastJson? FastJson is an open‑source JSON parsing library from Alibaba that can serialize Java objects to JSON strings and deserialize JSON strings back to Java objects. It is widely used by Java developers for its claimed high speed.
2. Is it really fast? A simple benchmark was performed on JDK 8, AMD 3700X, 3200 MHz RAM, comparing FastJson with the more popular Jackson and Google Gson. The test converted simple and complex objects to strings and back, each operation executed ten million times. The results (in milliseconds) show FastJson is about 20% faster than Jackson, while Gson is the slowest by a large margin.
Although FastJson appears fastest in this limited test, the study notes that memory usage and large‑document performance were not evaluated, and that speed alone should not be the sole criterion for library selection.
3. Popularity of FastJson Maven dependency statistics reveal that FastJson’s usage is far lower than Jackson and Gson, indicating it is not as popular. Community feedback (e.g., a 2016 Zhihu post) suggests FastJson suffers from lower code quality, though the author’s own projects have not encountered major bugs.
Issue tracking shows over 1.4 k unresolved issues, some of which are demonstrated below.
try {
String time = "1970-01-01 00:00:00";
JSONObject jsonObject = new JSONObject();
jsonObject.put("time", time);
Timestamp timestamp = jsonObject.getTimestamp("time");
System.out.println("time:" + timestamp);
System.out.println("/n");
} catch (Exception e) {
e.printStackTrace();
}The latest version still throws exceptions for certain timestamp formats. The underlying source code contains logic errors that allow malformed strings such as "1970-01-01 00:00:00.000000000.000000000" to be parsed while rejecting correct formats like "1970-01-01 00:00:00" or "1970-01-01 00:00:00.000".
if (strVal.endsWith(".000000000")) {
strVal = strVal.substring(0, strVal.length() - 10);
} else if (strVal.endsWith(".000000")) {
strVal = strVal.substring(0, strVal.length() - 7);
}
if (strVal.length() == 29 && strVal.charAt(4) == '-' && strVal.charAt(7) == '-' &&
strVal.charAt(10) == ' ' && strVal.charAt(13) == ':' && strVal.charAt(16) == ':' &&
strVal.charAt(19) == '.') {
int year = num(strVal.charAt(0), strVal.charAt(1), strVal.charAt(2), strVal.charAt(3));
int month = num(strVal.charAt(5), strVal.charAt(6));
int day = num(strVal.charAt(8), strVal.charAt(9));
int hour = num(strVal.charAt(11), strVal.charAt(12));
int minute = num(strVal.charAt(14), strVal.charAt(15));
int second = num(strVal.charAt(17), strVal.charAt(18));
int nanos = num(strVal.charAt(20), strVal.charAt(21), strVal.charAt(22), strVal.charAt(23),
strVal.charAt(24), strVal.charAt(25), strVal.charAt(26), strVal.charAt(27),
strVal.charAt(28));
return new Timestamp(year - 1900, month - 1, day, hour, minute, second, nanos);
}These bugs illustrate why FastJson is not as reliable as its name suggests.
4. Abandoning FastJson In the author’s projects, Spring Boot already brings Jackson, and the principle of minimal dependencies leads to preferring Jackson for JSON handling. Although some teammates still use Gson or FastJson, the author recommends standardizing on Jackson and gradually deprecating FastJson.
Readers are invited to share their own experiences and opinions.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.