jackson:http://jackson.codehaus.org/
json-lib:http://json-lib.sourceforge.net/
gson:http://code.google.com/p/google-gson/
Test environment:
1. Working computer: Intel Dual Core E8400 6GHz, Memory 4gb,winxp
2, Json-lib with the latest Jdk15,gson version is the latest V1.4,jackson is also the latest v1.5.5,jdk-v1.6.0_20,jmeter-v2.4
3, the test does not open any unrelated process, each completed a test after closing JMeter finishing memory, then the next test, each test run 3 times, averaging
4, JSON to Java bean meaning to convert JSON format to Java class, this class includes map, List, Date, Integer/long/double, string and other types of properties, Java Bean to JSON is the same. In addition, the two turn each other, the data of each conversion is randomly generated
Test Results:
* The higher the value of the throughput, the better, the lower the total time-consuming value, the better
JSON to bean,5 threads concurrently, about 200-byte objects, 10 million conversions:
|
Jackson |
Json-lib |
Gson |
| Tps |
64113.7 |
8067.4 |
13952.8 |
| Total time taken (seconds) |
155 |
1238 |
700 |
The bean goes json,5 threads concurrently, about 200 bytes of objects, 10 million conversions:
|
Jackson |
Json-lib |
Gson |
| Tps |
54802 |
15093.2 |
17308.2 |
| Total time taken (seconds) |
181 |
661 |
560 |
JSON to bean,5 threads concurrent, about 2K objects, 10 million conversions:
|
Jackson |
Json-lib |
Gson |
| Tps |
37314 |
2406.9 |
3657.50 |
| Total time taken (seconds) |
267 |
4120 |
2720 |
Bean to json,5 threads concurrent, about 2K objects, 10 million conversions:
|
Jackson |
Json-lib |
Gson |
| Tps |
30922.2 |
4274.8 |
4977.00 |
| Total time taken (seconds) |
322 |
2320 |
2000 |
Test Summary:
1 . Obviously, no matter what kind of conversion, Jackson > Gson > Json-lib.
Jackson's ability to deal with the json-lib is about 10 times times higher.
2, Json-lib seems to have stopped updating, the latest version is based on JDK15, and Jackson's community is more active;
3, While testing the performance, and the human flesh way to the three class library conversion correctness was checked , the three are up to 100% correct ;
4. Json-lib is cumbersome when converting a date type, as the following is the result of the conversion:
Json-lib:
{"Brithday": {"date": +, "Day": 2, "hours": 9, "minutes": +, "month": 7, "seconds": +, "time": 1282008266398, " Timezoneoffset ": -480," Year ": 110}}
Jackson:
{"Brithday": 1282008123101}
5, Json-lib dependentCommons series of packages and ezmorph pack of 5, and Jackson in addition to their own only rely on commons-logging
6. Jackson provides a complete node-based tree Model, as well as complete OJM data binding capabilities.
Jackson Use Example:
Jacksonmapper:
Created as a a hungry man singleton mode , Jackson used to convert the core class Objectmapper without having to new an object every time, a sentence on the official web: can reuse, share globally
Java code
- /**
- * @author Xuanyin
- *
- */
- Public class Jacksonmapper {
- /**
- *
- */
- private Static final Objectmapper mapper = new Objectmapper ();
- /**
- *
- */
- Private Jacksonmapper () {
- }
- /**
- *
- * @return
- */
- public static Objectmapper getinstance () {
- return mapper;
- }
- }
JSON to Bean:
Java code
- ......
- String json = "...";
- Objectmapper mapper = Jacksonmapper.getinstance ();
- Yourbean bean = Mapper.readvalue (JSON, new Yourbean (). GetClass ());
- ......
Bean to JSON:
Java code
- ......
- Yourbean bean = new Yourbean ();
- ......
- Objectmapper mapper = Jacksonmapper.getinstance ();
- StringWriter SW = new StringWriter ();
- Jsongenerator Gen = New Jsonfactory (). Createjsongenerator (SW);
- Mapper.writevalue (gen, Bean);
- Gen.close ();
- String json = sw.tostring ();
- ......
* Yourbean of the above two pieces of code can of course be the basic type of Java
JSON class library performance comparison between Jackson and Json-lib [go]