JSON is the abbreviation for JavaScript Object notation, a lightweight way to describe data, which is smaller, faster, and easier to parse than XML, and JSON has the advantage of cross-platform. In this next article we're going to compare 7 Java JSON libraries, and we'll measure the speed with which the JSON objects are converted to each other and to the file.
Jackson Library
Jackson is a "multi-purpose Java library with a goal of being faster, lighter and easier to use", and he offers 3 ways to work with JSON format
1. Streaming API: Ability to incrementally parse/generate JSON
2. Tree model: Describe JSON documents in memory in a tree-shaped structure
3. Data binding: JSON and Pojo convert each other
Goole-gson Library
The second is Gson, which also supports the conversion of JSON to Java objects, and requests strings that support JSON format to go directly to the Java object without the need to put annotation.
The advantage of Gson is that
1. Provide a Tojson () and Fromjson () method to achieve the interoperability of Java and JSON objects, very convenient
2. Support Java generics
3. Support for arbitrarily complex objects
4. Allow pre-existing unmodifiable objects-to is converted to and from JSON
5. Allow custom representation for objects
The next few JSON libraries are anonymous, and in the picture below you'll see their names.
Benchmark
Our test machine is configured to
2.5GHz I5 Processor, Win7 64-bit, 4GB DDR3 memory
The following pictures show the performance of the centralized JSON library.
As you can see, when serializing and deserializing small data, Gson is the fastest
When serializing a larger piece of data, Gson's performance was not good, and Jackson performed better.
For mobile users, the size of the jar package is also important, as you can see, the Gson jar package is quite small
Conclusion
Gson performance is better for small-scale data, and Jackson is faster for large-scale data
Comparison of several JSON libraries in JAVA