Fastjson Frequently Asked Questions

Source: Internet
Author: User
Tags stream api maven central

1. How to get Fastjson?

You can download Fastjson from the following places:

    • Maven Central Warehouse: http://central.maven.org/maven2/com/alibaba/fastjson/
    • sourceforge.net:https://sourceforge.net/projects/fastjson/files/
    • The latest version of how to configure Fastjson dependent Fastjson in Maven will be published to the MAVEN central repository, which you can rely on directly.
<dependency>     <groupid>com.alibaba</groupid>     <artifactid> fastjson</artifactid>     <version>1.2.21</version></dependency> 

Android version

<dependency>     <groupid>com.alibaba</groupid>     <artifactid> fastjson</artifactid>     <version>1.1.55.android</version></Dependency >       
2. What are the main APIs for Fastjson?

The Fastjson entry class is Com.alibaba.fastjson.JSON, and the main API is json.tojsonstring, and parseobject.

Com.alibaba.fastjson;         tojsonstring (<parseobject (class<features);}  

Serialization:

JSON. tojsonstring (obj);

Deserialization:

JSON. Parseobject ("... VO. Class);   

Generic deserialization:

Com.alibaba.fastjson.TypeReference; list<JSON. Parseobject ("... typereference<list<vo>> () {});      
3. Where to find Fastjson use examples

See here for examples of Fastjson use: Https://github.com/alibaba/fastjson/wiki/Samples-DataBind

4. What is the performance of Fastjson?

Fastjson is currently the fastest JSON library in the Java language, faster than claiming the fastest Jackson speed, and third-party independent test results here: https://github.com/eishay/jvm-serializers/wiki/Staging-Results.

Turn off the function of circular reference detection when performing a performance test on your own.

JSONserializerfeature.  Disablecircularreferencedetect)JSON. Parseobject ("... VOFeature.  Disablecircularreferencedetect)         

Here are the performance evaluations by Jackson author Cowtowncoder and others on Fastjson: https://groups.google.com/forum/#!topic/ Java-serialization-benchmarking/8es1koquahw

5. How does Fastjson performance compare to Gson?

Fastjson is about 6 times times faster than Gson, and the test results are here: https://github.com/eishay/jvm-serializers/wiki/Staging-Results.

6. Can the Fastjson be run on Android?

Fastjson has a dedicated for Android version, removing the infrequently used features. The jar occupies a smaller number of bytes. The GIT branch address is: https://github.com/alibaba/fastjson/tree/android.

7. Is Fastjson serialization required to configure the serialization of Java beans like json-lib?

No, Fastjson serialization and deserialization do not require special configuration, the only requirement is that the classes you serialize conform to the Java Bean specification.

8. Fastjson How to handle dates

The API for Fastjson processing dates is simple, for example:

JSON"Yyyy-mm-dd HH:mm:ss. SSS") 

Use ISO-8601 date format

JSONserializerfeature.  Useiso8601dateformat);  

Global Modification Date format

JSON"Yyyy-mm-dd";  JSONserializerfeature.  Writedateusedateformat);     

Deserialization can automatically recognize the following date formats:

    • ISO-8601 Date format
    • Yyyy-mm-dd
    • YYYY-MM-DD HH:mm:ss
    • Yyyy-mm-dd HH:mm:ss. Sss
    • Millisecond number
    • Millisecond numeric string
    • . NET JSON date format
    • New Date (198293238)
9. How do I customize serialization?

You can use the Simpleprepropertyfilter filter field to see more here: https://github.com/alibaba/fastjson/wiki/%E4%BD%BF%E7%94% A8simplepropertyprefilter%e8%bf%87%e6%bb%a4%e5%b1%9e%e6%80%a7

For more information on customizing serialization, see here: https://github.com/alibaba/fastjson/wiki/%E5%AE%9A%E5%88%B6%E5%BA%8F%E5%88%97%E5%8C%96

10. What if the serialized result browser is not supported when there is a reference to the object?

Use the Serializerfeature.disablecircularreferencedetect attribute to turn off reference detection and generation. For example:

String  JSONserializerfeature.  Disablecircularreferencedetect);   
One. IE 6 does not support JSON with Chinese strings, how to handle?

Fastjson provides browsercompatible this configuration, after opening, all Chinese will be serialized into \UXXXX This format, the number of bytes will be more, but can be compatible with IE 6.

String  JSONserializerfeature.  browsercompatible);   
Fastjson How to handle large objects and oversized JSON text

Fastjson provides the Stream API, see here for details Https://github.com/alibaba/fastjson/wiki/Stream-api

13. Customizing serialization with @jsonfield

Fastjson provides the ability to customize serialization and deserialization using annotation. Https://github.com/alibaba/fastjson/wiki/JSONField

14. Output null values in the object

By default Fastjson does not output the null value of the object, if you need to output a null value, see here HTTPS://GITHUB.COM/ALIBABA/FASTJSON/WIKI/WRITENULL_CN

Fastjson Frequently Asked Questions

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.