Is FastJson Really Faster? Benchmark vs Jackson and Gson

This article examines FastJson’s claim of speed by benchmarking it against Jackson and Gson, analyzes test results, discusses its popularity, highlights critical bugs in its timestamp handling, and ultimately recommends abandoning FastJson in favor of more widely adopted JSON libraries.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Is FastJson Really Faster? Benchmark vs Jackson and Gson

1. Why FastJson?

FastJson is Alibaba’s open‑source JSON library that can parse JSON strings, serialize Java beans to JSON, and deserialize JSON back to Java objects. It is popular among Java developers because of its advertised high performance.

2. Is it really fast?

A simple benchmark compares FastJson with the widely used Jackson and Google’s Gson. The test runs on JDK 8, AMD 3700X, 3200 MHz RAM, converting simple and complex objects to and from strings ten million times. Results (in milliseconds) show FastJson is about 20% faster than Jackson, while Gson is the slowest.

Although FastJson wins the speed test, the study does not cover memory usage or large‑document performance. In real applications even the slowest library (Gson) usually meets requirements, and factors such as I/O optimization and parallel processing are more important than raw parsing speed.

3. FastJson isn’t that popular

FastJson’s Maven dependency count is far lower than Jackson’s, and it lacks the extensive ecosystem of the Jackson family. Community feedback on sites like Zhihu points out that FastJson suffers from low code quality, with 1,283 unresolved issues at the time of writing.

The following test code was used for the benchmark:

try {<br/>    String time = "1970-01-01 00:00:00";<br/>    com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();<br/>    jsonObject.put("time", time);<br/><br/>    Timestamp timestamp = jsonObject.getTimestamp("time");<br/>    System.out.println("time:" + timestamp);<br/>} catch (Exception e) {<br/>    e.printStackTrace();<br/>}

When using the latest FastJson version, a timestamp parsing bug appears in the library’s source code:

if (strVal.endsWith(".000000000")) {<br/>    strVal = strVal.substring(0, strVal.length() - 10);<br/>} else if (strVal.endsWith(".000000")) {<br/>    strVal = strVal.substring(0, strVal.length() - 7);<br/>}<br/><br/>if (strVal.length() == 29 && strVal.charAt(4) == '-' && strVal.charAt(7) == '-' && strVal.charAt(10) == ' ' && strVal.charAt(13) == ':' && strVal.charAt(16) == ':' && strVal.charAt(19) == '.') {<br/>    int year = num(strVal.charAt(0), strVal.charAt(1), strVal.charAt(2), strVal.charAt(3));<br/>    int month = num(strVal.charAt(5), strVal.charAt(6));<br/>    int day = num(strVal.charAt(8), strVal.charAt(9));<br/>    int hour = num(strVal.charAt(11), strVal.charAt(12));<br/>    int minute = num(strVal.charAt(14), strVal.charAt(15));<br/>    int second = num(strVal.charAt(17), strVal.charAt(18));<br/>    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));<br/>    return new Timestamp(year - 1900, month - 1, day, hour, minute, second, nanos);<br/>}

This logic incorrectly accepts malformed timestamps such as “1970-01-01 00:00:00.000000000.000000000” while rejecting correct formats like “1970-01-01 00:00:00” or “1970-01-01 00:00:00.000”.

Combined with community criticism, the evidence suggests FastJson is not as robust as its name implies.

4. Drop FastJson

In projects that already use Spring Boot, Jackson is the default JSON processor. Following the “minimal dependencies” principle, the author recommends standardizing on Jackson and gradually removing FastJson and Gson from the codebase.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaperformancefastjsonGsonJacksonjson-parsing
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.