Skip to content
This repository

Module that adds support for JAXB annotations as an alternative to "native" Jackson annotations

update to new parent pom

latest commit 2f4b707e89
Tatu Saloranta authored
Octocat-spinner-32 release-notes Fix compilation issues wrt 2.4 January 28, 2014
Octocat-spinner-32 src add a javadoc March 26, 2014
Octocat-spinner-32 .gitignore ... November 07, 2011
Octocat-spinner-32 README.md ... April 22, 2013
Octocat-spinner-32 create-test-report.sh add unit test report generation December 24, 2011
Octocat-spinner-32 pom.xml update to new parent pom April 14, 2014
README.md

Overview

This Jackson extension module provides support for using JAXB (javax.xml.bind) annotations as an alternative to native Jackson annotations. It is most often used to make it easier to reuse existing data beans that used with JAXB framework to read and write XML.

Status

Module is fully usable, as it is based on earlier "jackson-xc" jar that was part of Jackson distribution in 1.x versions.

For Jackson 2.0 functionality will be only offered through this module.

Maven dependency

To use this extension on Maven-based projects, use following dependency:

<dependency>
  <groupId>com.fasterxml.jackson.module</groupId>
  <artifactId>jackson-module-jaxb-annotations</artifactId>
  <version>2.2.0</version>
</dependency>

(or whatever version is most up-to-date at the moment)

Usage

To enable use of JAXB annotations, one must add JaxbAnnotationIntrospector provided by this module. There are two ways to do this:

  • Register JaxbAnnotationModule, or
  • Directly add JaxbAnnotationIntrospector

Module registration works in standard way:

JaxbAnnotationModule module = new JaxbAnnotationModule();
// configure as necessary
objectMapper.registerModule(module);

and the alternative -- explicit configuration is done as:

AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// if ONLY using JAXB annotations:
mapper.setAnnotationIntrospector(introspector);
// if using BOTH JAXB annotations AND Jackson annotations:
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
mapper.setAnnotationIntrospector(new AnnotationIntrospector.Pair(introspector, secondary);

Note that by default Module version will use JAXB annotations as the primary, and Jackson annotations as secondary source; but you can change this behavior

(need to add example here!)

Something went wrong with that request. Please try again.