Getting started with Jackson - Jackson Tutorial


The Java JSON API called Jackson consists of one core JAR file (project) and two other JAR files that use the core JAR file. The three JAR files (projects) in the Jackson JSON API are:

  • Jackson Core
  • Jackson Annotations
  • Jackson Databind

These projects use each other in that sequence too. Jackson Annotation uses the Jackson Core features, and the Jackson Databind uses Jackson Annotation.

In order to “install” Jackson in your Java application you need to add these JAR files to the classpath of your application. There are several ways to do so. I will cover two here.


1. Jackson Maven Dependencies

If your project uses Maven to build (and resolve + download dependencies), you need to add Jackson as a dependency to your project’s POM file. Here is how Jackson as Maven dependencies look:

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

Note, that both jackson-annotations and jackson-databind have “transitive dependencies” to jackson-core (and jackson-databind to jackson-annotations). This means, that if you plan to use the jackson-databind project, you just need to include that as dependency in your Maven POM file. Then it will transitively include the other two projects as dependencies. Regardless, I like to add my dependencies explicitly so I can see what I am using (but that’s just me).


2. Adding the JAR Files Directly to the Classpath

Another option is to add the Jackson JAR files directly to the classpath of your application. To do so you must first download the JAR files. You can download the finished JAR files via the central Maven repository. Go to:

http://search.maven.org

Search for the project you want to use (e.g. jackson-core, jackson-annotation or jackson-databind). Once you find the right project, make sure you click the “all versions” link next to the version number in the search result. That will show you a list of the previous versions of that project. Click around until you find a link directly to the JAR file for that project and that version. Then download the JAR file.

Once the JAR files are downloaded, add them to the classpath of your project. You can do so within your IDE, and / or within the scripts (bash or cmd) you use to run your application.