This directory contains the source code for fastjson2, a high-performance Java library for processing JSON. It is the next generation of the popular fastjson library (v1), offering significant performance improvements and enhanced features while addressing security concerns present in v1.
Key features of fastjson2 include:
- High Performance: Outperforms other popular JSON libraries like Jackson and Gson.
- Modern JDK Support: Compatible with JDK 8 and newer versions, including optimizations for newer features.
- JSONPath Support: Advanced querying capabilities using SQL:2016 compliant JSONPath syntax.
- Cross-Platform: Supports Android 8+.
- Kotlin Integration: Dedicated module for seamless use with Kotlin.
- JSON Schema: Support for validating JSON against schemas.
- JSONB Format: Support for a binary JSON format for even faster processing.
- Framework Extensions: Modules for integration with Spring Framework, Solon, and JAX-RS.
The project is structured as a multi-module Maven project.
pom.xml: The root Maven Project Object Model (POM) file defining the parent project and managing dependencies and build configuration for all submodules.README.md: The main project documentation in Chinese, detailing features, usage, and modules.README_EN.md: The English version of the main project documentation.CONTRIBUTING.md: Guidelines for contributing to the project.core/: The mainfastjson2library module.kotlin/: Module providing Kotlin-specific extensions and support.extension/: Core extensions for features like Arrow, ClickHouse, etc.extension-spring5/,extension-spring6/,extension-solon/,extension-jaxrs/: Modules for integrating fastjson2 with various web frameworks.fastjson1-compatible/: Module for compatibility with fastjson v1.x.benchmark/: Contains JMH benchmarks for performance testing.example-*: Example projects demonstrating usage with different frameworks.docs/: Additional documentation files.
This is a Java/Maven project. The primary build tool is Maven.
- Java JDK 8 or higher.
- Apache Maven 3.3.9 or higher.
-
Clean: Remove build artifacts.
mvn clean
-
Compile: Compile the source code.
mvn compile
-
Test: Run unit and integration tests.
mvn test -
Package: Package the compiled code into JAR files.
mvn package
-
Install: Install the package into the local Maven repository.
mvn install
-
Validate: Check the project for correctness and adherence to coding standards (Checkstyle, Modernizer).
mvn validate
-
Build Everything: Clean, compile, test, and package.
mvn clean package
To run the JMH benchmarks:
- Navigate to the
benchmarkdirectory or run from the root:Or from the root:cd benchmark mvn clean package java -jar target/fastjson2-benchmarks.jarmvn clean package -pl benchmark -am java -jar benchmark/target/fastjson2-benchmarks.jar
- Language: Java (Primary), Kotlin (for
kotlinmodule). - Build Tool: Apache Maven.
- Testing: Unit and integration tests are written using JUnit 5 and Kotest. Test dependencies are managed in the root
pom.xml. - Code Style: The project uses Checkstyle for code formatting and style checks. The configuration is located in
src/checkstyle/fastjson2-checks.xml. Thevalidatephase enforces these rules. - Modernizer: The build process includes the Modernizer Maven plugin to detect uses of legacy Java APIs.
- Contributing: Follow the guidelines in
CONTRIBUTING.md. Ensuremvn validateandmvn testpass before submitting pull requests. Pull requests should be small and focused.