Now that the introductions are out of the way let’s get to it. After searching the documentation for Jackson I didn’t see a tutorial on using the Jackson plug-in for Maven. I knew it was simple to setup if you knew the Maven repository and artifact name. I looked but couldn’t find the repository in the documentation. I did a little digging and eventually found it out. Below is an example and a few snippets to get you started.
Step 1: Add the Repository
This change is made in your pom.xml file. If you don’t have a repositories tag in your pom.xml you will have to add one. Please take a look at the project in the zip file further down to see it in action. The key here is that Jackson is in the Codehaus Maven Repository. That is where I spent the most time figuring this out.
Step 2: Add the dependency
There are a total of six artifacts in Jackson 1.6. I found a list on this page. I only need one for the example in the test. In my pom.xml I added the following to my dependencies section.
Step 3: Create and use a Mapper
In JacksonTest.java I show how to create and use the Mapper. To serialize a basic object like a String, its three lines of code in this example. Look at lines 35, 45, and 59.
MavenJacksonPlugin.zip - Here is a Maven project that shows all of the components together. I released the test under the Apache Software License. Please abide by the terms of the license if you choose to use it.
JSON data binding performance: Jackson vs Google-gson vs BerliOS JSON Tools - A performance test that shows Jackson outperforming Google’s Gson.