Upgrading Jackson 1.9 to 2.0
This page lists common steps needed to upgrade code that uses Jackson 1.9 (or, earlier versions; but if so, may need more work) to work with Jackson 2.0.
Note that this is an incomplete, work-in-progress document: help us make it better by contribution additional notes!
Update Maven / JAR dependencies
The first thing to do is to upgrade jars. Depending on your build system, you can either get jars from Jackson Download page, or update Maven dependencies. New Maven dependencies are:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.0.0</version> </dependency>
The main thing to note is that instead of 2 jars ("core", "mapper"), there are now 3: former core has been split into separate "annotations" package and remaining "core"; latter contains streaming/incremental parser/generator components. And "databind" is a direct replacement of "mapper" jar.
Similarly, you will need to update dependencies to supporting jars like:
- Mr Bean: com.fasterxml.jackson.module / jackson-module-mrbean
- Smile binary JSON format: com.fasterxml.jackson.dataformat / jackson-dataformat-smile
- JAX-RS JSON provider: com.fasterxml.jackson.jaxrs / jackson-jaxrs-json-provider
- JAXB annotation support ("xc"): com.fasterxml.jackson.module / jackson-module-jaxb-annotations
these, and many many more extension modules have their own project pages under FasterXML Git repo.
Change import statements
Since Jackson 2.0 code lives in Java packages, you will need to change import statements. Although most changes are mechanical, there isn't strict set of mappings. The way I have done this is to simply use an IDE like Eclipse, and remove all invalid import statements; and then use Eclipse functionality to find new packages. Typical import changes include:
It is often convenient to just use wildcards imports for main categories (com.fasterxml.jackson.core.*, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.annotation.*)
The next biggest change was that of refactoring on/off Features, formerly defined as inner Enums of SerializationConfig and DeserializationConfig classes. For 2.0, enums were moved to separate stand-alone enums:
Entries that were NOT moved along are ones that were shared by both, and instead were added into new MapperFeature enumeration, for example:
Tree model method name changes (JsonNode)
Although many methods (and some classes) were renamed here and there, mostly these were one-offs. But one area where major naming changes were done was with Tree Model -- this because 1.x names were found to be rather unwieldy and unnecessarily verbose. So we decided that it would make sense to try to do a "big bang" name change with 2.0, to get to a clean(er) baseline.
Changes made were mostly of following types:
getXxxValue() shortened to xxxValue(): getTextValue() -> textValue(), getFieldNames() -> fieldNames() and so on.
getXxxAsYyy() shortened to asYyy(): getValueAsText() -> asText()
Deprecated classes were removed; this includes:
It is possible to make 2.0 databinder recognize 1.x annotations, using 2.0 implementation of AnnotationIntrospector from this project: