Convert Figma logo to code with AI

FasterXML logojackson

Main Portal page for the Jackson project

9,031
1,189
9,031
0

Top Related Projects

23,230

A Java serialization/deserialization library to convert Java Objects into JSON and back

25,713

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

9,685

A modern JSON library for Kotlin and Java.

1,505

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go

Quick Overview

Jackson is a popular, high-performance JSON processor for Java. It provides a suite of data-processing tools, including the flagship streaming JSON parser and generator, and data binding capabilities that can convert Java objects to and from JSON.

Pros

  • Fast and efficient JSON processing
  • Flexible and extensible architecture
  • Supports various data formats beyond JSON (e.g., XML, YAML, CSV)
  • Excellent integration with many Java frameworks and libraries

Cons

  • Learning curve for advanced features
  • Can be complex for simple use cases
  • Some inconsistencies in API design across modules
  • Occasional breaking changes between major versions

Code Examples

  1. Serializing a Java object to JSON:
ObjectMapper mapper = new ObjectMapper();
User user = new User("John Doe", 30);
String json = mapper.writeValueAsString(user);
System.out.println(json);
  1. Deserializing JSON to a Java object:
String json = "{\"name\":\"John Doe\",\"age\":30}";
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(json, User.class);
System.out.println(user.getName());
  1. Reading JSON from a file:
ObjectMapper mapper = new ObjectMapper();
File file = new File("user.json");
User user = mapper.readValue(file, User.class);
  1. Using Jackson annotations:
public class User {
    @JsonProperty("full_name")
    private String name;
    
    @JsonIgnore
    private String password;
    
    // getters and setters
}

Getting Started

To use Jackson in your Java project, first add the following dependency to your Maven pom.xml:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.13.0</version>
</dependency>

Then, you can start using Jackson in your code:

import com.fasterxml.jackson.databind.ObjectMapper;

public class Example {
    public static void main(String[] args) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = "{\"name\":\"John Doe\",\"age\":30}";
        User user = mapper.readValue(json, User.class);
        System.out.println(user.getName());
    }
}

This example demonstrates how to deserialize a JSON string into a Java object using Jackson's ObjectMapper.

Competitor Comparisons

23,230

A Java serialization/deserialization library to convert Java Objects into JSON and back

Pros of Gson

  • Simpler API and easier to use for basic JSON operations
  • Smaller library size, leading to reduced application footprint
  • Better performance for simple, straightforward JSON parsing tasks

Cons of Gson

  • Less flexible for complex JSON structures and custom serialization
  • Fewer features and customization options compared to Jackson
  • Limited support for handling polymorphic types

Code Comparison

Jackson:

ObjectMapper mapper = new ObjectMapper();
MyObject obj = mapper.readValue(jsonString, MyObject.class);
String json = mapper.writeValueAsString(obj);

Gson:

Gson gson = new Gson();
MyObject obj = gson.fromJson(jsonString, MyObject.class);
String json = gson.toJson(obj);

Both Jackson and Gson are popular JSON libraries for Java, with Jackson offering more features and flexibility, while Gson provides a simpler API and better performance for basic tasks. Jackson is generally preferred for complex applications with diverse JSON handling needs, while Gson is often chosen for simpler projects or when minimizing library size is a priority. The choice between the two depends on the specific requirements of the project and the developer's familiarity with each library.

25,713

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

Pros of fastjson

  • Generally faster parsing and serialization performance
  • Simpler API and easier to use for basic JSON operations
  • Smaller library size, leading to reduced application footprint

Cons of fastjson

  • Less comprehensive feature set compared to Jackson
  • Lower adoption and community support outside of China
  • Some security vulnerabilities have been reported in the past

Code Comparison

fastjson:

JSONObject jsonObject = JSON.parseObject(jsonString);
String name = jsonObject.getString("name");
int age = jsonObject.getIntValue("age");

Jackson:

ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(jsonString);
String name = jsonNode.get("name").asText();
int age = jsonNode.get("age").asInt();

Both libraries offer straightforward ways to parse JSON, but fastjson's API is slightly more concise. However, Jackson provides more robust type handling and configuration options, which can be beneficial for complex use cases.

While fastjson excels in performance and simplicity, Jackson offers a more comprehensive ecosystem with better documentation and wider adoption in the global developer community. The choice between the two often depends on specific project requirements, performance needs, and the development team's familiarity with each library.

9,685

A modern JSON library for Kotlin and Java.

Pros of Moshi

  • Smaller library size and faster performance
  • Designed specifically for Kotlin, with excellent Kotlin support
  • Simpler API and easier to use for basic JSON operations

Cons of Moshi

  • Less feature-rich compared to Jackson's extensive functionality
  • Smaller community and ecosystem of extensions
  • Limited support for advanced data binding and custom serialization

Code Comparison

Jackson:

ObjectMapper mapper = new ObjectMapper();
MyObject obj = mapper.readValue(jsonString, MyObject.class);
String json = mapper.writeValueAsString(obj);

Moshi:

val moshi = Moshi.Builder().build()
val adapter = moshi.adapter(MyObject::class.java)
val obj = adapter.fromJson(jsonString)
val json = adapter.toJson(obj)

Both libraries offer straightforward JSON serialization and deserialization, but Moshi's API is slightly more concise, especially when used with Kotlin. Jackson provides more configuration options out of the box, while Moshi focuses on simplicity and Kotlin integration.

Jackson is more suitable for complex Java projects with diverse JSON processing needs, while Moshi excels in Kotlin-based Android development and simpler use cases where performance and ease of use are prioritized over extensive features.

1,505

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go

Pros of json-iterator/java

  • Significantly faster parsing and serialization performance
  • Lower memory usage during operations
  • Simpler API with fewer dependencies

Cons of json-iterator/java

  • Less mature and less widely adopted than Jackson
  • Fewer features and customization options
  • Limited support for advanced data binding scenarios

Code Comparison

json-iterator/java:

JsonIterator iter = JsonIterator.parse(input);
User user = iter.read(User.class);

Jackson:

ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(input, User.class);

Both libraries offer straightforward APIs for parsing JSON, but json-iterator/java tends to be more concise. Jackson provides more extensive configuration options and supports a wider range of data binding scenarios.

json-iterator/java excels in performance-critical applications where raw speed is crucial. It's particularly well-suited for scenarios involving large volumes of JSON data or systems with limited resources.

Jackson, on the other hand, offers a more comprehensive feature set and greater flexibility. It's better suited for complex applications that require advanced data binding, custom serialization/deserialization, or integration with various data formats beyond JSON.

The choice between the two libraries ultimately depends on the specific requirements of your project, balancing performance needs against feature richness and ecosystem support.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Open Source

Jackson Project Home @github

This is the home page of the Jackson Project.

What is New?

(note: for up-to-date release info, see Jackson Releases)

What is Jackson?

Jackson has been known as "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java".

More than that, Jackson is a suite of data-processing tools for Java (and the JVM platform), including the flagship streaming JSON parser / generator library, matching data-binding library (POJOs to and from JSON) and additional data format modules to process data encoded in Avro, BSON, CBOR, CSV, Smile, (Java) Properties, Protobuf, TOML, XML or YAML; and even the large set of data format modules to support data types of widely used data types such as Guava, Joda, PCollections and many, many more (see below).

While the actual core components live under their own projects -- including the three core packages (streaming, databind, annotations); data format libraries; data type libraries; JAX-RS provider; and a miscellaneous set of other extension modules -- this project act as the central hub for linking all the pieces together.

A good companion to this README is the Jackson Project FAQ.

Actively developed versions

Jackson suite has two major versions: 1.x is deprecated and no versions are released; 2.x is the actively developed version. These two major versions use different Java packages and Maven artifact ids, so they are not mutually compatible, but can peacefully co-exist: a project can depend on both Jackson 1.x and 2.x, without conflicts. This is by design and was chosen as the strategy to allow smoother migration from 1.x to 2.x.

The latest stable versions from these branches are:

  • 2.17.2, released on 05-Jul-2024
    • 2.16.2 is the latest patch from previous stable branch
  • 1.9.13, released 14-Jul-2013

Recommended way to use Jackson is through Maven repositories; releases are made to Central Maven Repository (CMR). Individual projects' wiki pages sometimes also contain direct download links, pointing to CMR.

Release notes for 2.x releases are found from Jackson Releases page.

Active Jackson projects

Most projects listed below are lead by Jackson development team; but some by other at-large Jackson community members. We try to keep versioning of modules compatible to reduce confusion regarding which versions work together.

Core modules

Core modules are the foundation on which extensions (modules) build upon. There are 3 such modules currently (as of Jackson 2.x):

  • Streaming (docs) ("jackson-core") defines low-level streaming API, and includes JSON-specific implementations
  • Annotations (docs) ("jackson-annotations") contains standard Jackson annotations
  • Databind (docs) ("jackson-databind") implements data-binding (and object serialization) support on streaming package; it depends both on streaming and annotations packages

Third-party datatype modules

These extensions are plug-in Jackson Modules (registered with ObjectMapper.registerModule()), and add support for datatypes of various commonly used Java libraries, by adding serializers and deserializers so that Jackson databind package (ObjectMapper / ObjectReader / ObjectWriter) can read and write these types.

Datatype modules directly maintained by Jackson team are under the following Github repositories:

In addition, we are aware of additional modules that are not directly maintained by core Jackson team:

Providers for JAX-RS

Jackson JAX-RS Providers has handlers to add dataformat support for JAX-RS implementations (like Jersey, RESTeasy, CXF). Providers implement MessageBodyReader and MessageBodyWriter. Supported formats currently include JSON, Smile, XML, YAML and CBOR.

Data format modules

Data format modules offer support for data formats other than JSON. Most of them simply implement streaming API abstractions, so that databinding component can be used as is; some offer (and few require) additional databind level functionality for handling things like schemas.

Currently following data format modules are fully usable and supported (version number in parenthesis, if included, is the first Jackson 2.x version to include module; if missing, included from 2.0)

  • Avro: supports Avro data format, with streaming implementation plus additional databind-level support for Avro Schemas
  • CBOR: supports CBOR data format (a binary JSON variant).
  • CSV: supports Comma-separated values format -- streaming api, with optional convenience databind additions
  • Ion (2.9): support for Amazon Ion binary data format (similar to CBOR, Smile, i.e. binary JSON - like)
  • (Java) Properties (2.8): creating nested structure out of implied notation (dotted by default, configurable), flattening similarly on serialization
  • Protobuf (2.6): supported similar to Avro
  • Smile: supports Smile (binary JSON) -- 100% API/logical model compatible via streaming API, no changes for databind
  • TOML: (NEW in upcoming 2.13) supports TOML, supported with both streaming and databind implementations
  • XML: supports XML; provides both streaming and databind implementations. Similar to JAXB' "code-first" mode (no support for "XML Schema first", but can use JAXB beans)
  • YAML: supports YAML, which being similar to JSON is fully supported with simple streaming implementation

There are also other data format modules, provided by developers outside Jackson core team:

  • BEncode: support for reading/writing BEncode (BitTorrent format) encoded data
  • bson4jackson: adds support for BSON data format (by Mongo project).
    • Implemented as full streaming implementation, which allows full access (streaming, data-binding, tree-model)
    • Also see [MongoJack] library below; while not a dataformat module, it allows access to BSON data as well.
  • EXIficient supports Efficient XML Interchange
  • jackson-dataformat-msgpack adds support MessagePack (aka MsgPack) format
    • Implemented as full streaming implementation, which allows full access (streaming, data-binding, tree-model)
  • HOCON: experimental, partial implementation to support HOCON format -- work in progress
  • Rison: Jackson backend to support Rison

JVM Language modules

  • Kotlin to handle native types of Kotlin
  • Scala to handle native Scala types (including but not limited to Scala collection/map types, case classes)
    • Currently (October 2022) Scala 2.11, 2.12, 2.13 and 3 are supported (2.9 was supported up to Jackson 2.3 and 2.10 up to Jackson 2.11)

Support for Schemas

Jackson annotations define intended properties and expected handling for POJOs, and in addition to Jackson itself using this for reading/writing JSON and other formats, it also allows generation of external schemas. Some of this functionality is included in above-mentioned data-format extensions; but there are also many stand-alone Schema tools, such as:

JSON Schema

Other schema languages

Other modules, stable

Other fully usable modules by FasterXML team include:

  • Base modules:
    • Afterburner: speed up databinding by 30-40% with bytecode generation to replace use of Reflection for field access, method/constructor calls
    • Guice: extension that allows injection values from Guice injectors (and basic Guice annotations), instead of standard @JacksonInject (or in addition to)
    • JAXB Annotations: allow use of JAXB annotations as an alternative (in addition to or instead of) standard Jackson annotations
    • Mr Bean: "type materialization" -- let Mr Bean generate implementation classes on-the-fly (NO source code generation), to avoid monkey code
    • OSGi: allows injection of values from OSGi registry, via standard Jackson @JacksonInject annotation
    • Paranamer: tiny extension for automatically figuring out creator (constructor, factory method) parameter names, to avoid having to specify @JsonProperty.

Jackson jr

While Jackson databind is a good choice for general-purpose data-binding, its footprint and startup overhead may be problematic in some domains, such as mobile phones; and especially for light usage (couple of reads or writes). In addition, some developers find full Jackson API overwhelming.

For all these reasons, we decided to create a much simpler, smaller library, which supports a subset of functionality, called Jackson jr. It builds on Jackson Streaming API, but does not depend on databind. As a result its size (both jar, and runtime memory usage) is considerably smaller; and its API is very compact.

Third-party non-module libraries based on Jackson

Jackson helper libraries

  • Jackson Ant path filter adds powerful filtering of properties to serialize, using Ant Path notation for hierarchic filtering

Support for datatypes

Other things related to or inspired by Jackson

  • Jackson-js is a Javascript/Node object serialization/deserialization library with API inspired by Jackson
  • Pyckson is a Python library that aims for same goals as Java Jackson, such as Convention over Configuration
  • Rackson is a Ruby library that offers Jackson-like functionality on Ruby platform

Contributing

If you would like to help with Jackson project, please check out Contributing.

You may also want to check out:

Support

Community support

Jackson components are supported by the Jackson community through mailing lists, Gitter forum, Github issues. See Contributing for full details.

Enterprise support

In addition to free (for all) community support, enterprise support—starting with version 2.10—is available as part of the Tidelift Subscription for (most) Jackson components.

The maintainers of Jackson and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Reporting security vulnerabilities

The recommended mechanism for reporting possible security vulnerabilities follows so-called "Coordinated Disclosure Plan" (see definition of DCP for general idea). The first step is to file a Tidelift security contact: Tidelift will route all reports via their system to maintainers of relevant package(s), and start the process that will evaluate concern and issue possible fixes, send update notices and so on. Note that you do not need to be a Tidelift subscriber to file a security contact.

Alternatively you may also report possible vulnerabilities to info at fasterxml dot com mailing address. Note that filing an issue to go with report is fine, but if you do that please DO NOT include details of security problem in the issue but only in email contact. This is important to give us time to provide a patch, if necessary, for the problem.

Note on reporting Bugs

Jackson bugs need to be reported against component they affect: for this reason, issue tracker is not enabled for this project. If you are unsure which specific project issue affects, the most likely component is jackson-databind, so you would use Jackson Databind Issue Tracker.

For suggestions and new ideas, try Jackson Future Ideas

Documentation

Web sites

Tutorials

For first-time users there are many good Jackson usage tutorials, including general usage / JSON tutorials:

and more specific tutorials:

Reports

Following reports have been published about Jackson components

Java JSON library comparisons

Since you probably want opinions by Java developers NOT related to Jackson project, regarding which library to use, here are links to some of existing independent comparisons:

NPM DownloadsLast 30 Days