Comparison of several JSON libraries in JAVA

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.