Ali latest JSON parsing library released, performance crushing fastjson and jackson

Ali latest JSON parsing library released, performance crushing fastjson and jackson

2022-10-19 0 865
Resource Number 46088 Last Updated 2025-02-24
¥ 0HKD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends a Ali open source high-performance JSON library – FASTJSON2.

Ali latest JSON parsing library released, performance crushing fastjson and jackson插图

FASTJSON2 is an important upgrade to the FASTJSON project, with the goal of providing a high-performance JSON library for the next decade. Through the same API,

  • Supports both JSON/JSONB protocols
  • Support full and partial parsing
  • Support Java server, client Android, big data scenarios
  • Kotlin
  • Support for Android (2.0.3.android)
  • Support Graal Native Image (2.0.3.graal)

Preparation

Add dependencies

Maven:

< dependency> 

< groupId> com.alibaba.fastjson2< /groupId> 

< artifactId> fastjson2< /artifactId> 

< version> 2.0.3< /version> 

< /dependency> 

Gradle:

dependencies {

implementation  'com. Alibaba. Fastjson2: fastjson2:2.0.3' < / span >

}

Other modules

  • Fastjson v1 compatible module

If you used fastjson 1.2.x version, you can use the compatibility package, the compatibility package cannot guarantee 100% compatibility, please carefully test and verify, and please timely feedback if you find any problems.

Maven:

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>fastjson</artifactId>

<version>2.0.3</version>

</dependency>

Gradle:

dependencies {

implementation 'com.alibaba:fastjson:2.0.3'

}
  • Kotlin Integration module

If the project uses Kotlin, you can use the fastjson-kotlin module, which uses the characteristics of kotlin.

Maven:

< dependency> 

< groupId> com.alibaba.fastjson2< /groupId> 

< artifactId> fastjson2-kotlin< /artifactId> 

< version> 2.0.3< /version> 

< /dependency> 

Gradle:

dependencies {

implementation(<span ">" class = "HLJS - string com. Alibaba. Fastjson2: fastjson2 - kotlin: 2.0.3" < / span >)

}

Simple use

In fastjson v2, the package is not the same as 1.x, it is com.alibaba.fastjson2. If you were using fastjson1, in most cases you can simply change the package name.

Parse JSON to JSONObject

String text = "..." ;
JSONObject data = JSON.parseObject(text);

byte[] bytes = ... ;
JSONObject data = JSON.parseObject(bytes); 

Parse JSON to JSONArray

String text = "..." ;
JSONArray data = JSON.parseArray(text); 

Parsing JSON into Java objects

String text = "..." ;
User data = JSON.parseObject(text,  User.class); 

Serializes Java objects to JSON

Object data = "..." ;
String text = JSON.toJSONString(data);
byte[] text = JSON.toJSONBytes(data); 

Use JSONObject, JSONArray

Get simple properties

String text = "{\"id\": 2,\"name\": \"fastjson2\"}";
JSONObject obj = JSON.parseObject(text);

int id = obj.getIntValue("id");
String name = obj.getString("name"); 

Read JavaBean

JSONArray array = ...
JSONObject obj = ...

User user = array.getObject(0, User.class);
User user = obj.getObject("key", User.class);

转为JavaBean

JSONArray array = ...
JSONObject obj = ...

User user = obj.toJavaObject(User.class);
List<User> users = array.toJavaList(User.class);

Serializes JavaBean objects to JSON

class User {
public int id;
public String name;
}

User user = new User();
user.id = 2;
user.name = "FastJson2";

String text = JSON.toJSONString(user);
byte[] bytes = JSON.toJSONBytes(user); 

Serialization result

{

"id" : 2,

"name" : "FastJson2"

}

Advanced use

Use JSONB

Serializing a JavaBean object JSONB

User user = ... ;
byte[] bytes = JSONB.toBytes(user);
byte[] bytes = JSONB.toBytes(user, JSONWriter.Feature.BeanToArray); 

Parsing JSONB data to JavaBean

byte[] bytes = ...
User user = JSONB.parseObject(bytes, User.class);
User user = JSONB.parseObject(bytes, User.class,  JSONReader.Feature.SupportBeanArrayMapping); 

Use JSONPath

Read some data using JSONPath

String text = ... ;

JSONPath path = JSONPath.of("$.id");  // Caching and reuse improves performance 

JSONReader parser = JSONReader.of(text);

Object result = path.extract(parser); 

Read part of byte[] using JSONPath

byte[] bytes = ... ;

JSONPath path = JSONPath.of("$.id");  // Caching and reuse can improve performance

JSONReader parser = JSONReader.of(bytes);

Object result = path.extract(parser); 

Read part of byte[] data using JSONPath

byte[] bytes = ... ;

JSONPath path = JSONPath.of("$.id");  // Caching and reuse improves performance 

JSONReader parser = JSONReader.ofJSONB(bytes);  // Note that the ofJSONB method is used here 

Object result = path.extract(parser); 

—END—

Open source protocol: Apache2.0

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free Source Code Ali latest JSON parsing library released, performance crushing fastjson and jackson https://ictcoder.com/ali-latest-json-parsing-library-released-performance-crushing-fastjson-and-jackson/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services