JAXB (Java Architecture for XML Binding) allows mapping Java classes to XML representations.
Starting from version 2.0, JAXB is heavily based on Java annotations to define Java/XML mappings. In order to be able to marshal your objects into XML and umarshall objects from XML, you first need to have your classes annotated with JAXB annotations. You can do this manually with your existing classes or you can use a schema compiler to compile your XML schema into a set of schema-derived classes which will contain all the required annotations.
The problem is that JAXB does not provide any alternatives to reading Java/XML mapping from annotations. If you're using JAXB, you're forced to have your mappings defined with Java annotations - with all the limitations I've mentioned in the user guide. Like, you can't annotate third-party classes, you can't provide alternative annotations for already annotated classes and so on.
Annox provides a solution for this problem.
JAXB reference implementation can be configured with a special annotation reader which may implement a different strategy for reading annotations. Annox takes advantage of this feature and implements an annotation reader which can load JAXB annotations from XML.
Using Annox annotation reader with JAXB RI
Before you start with Annox annotation reader for JAXB RI, I highly recommend reading the Annox user guide in order to understand core Annox concepts.
Using Annox annotation reader with JAXB RI is really very simple. You just have to create an instance of
AnnoxAnnotationReader and set it as
JAXBRIContext.ANNOTATION_READER property of the JAXB context:
See Purchase Order Sample for an working example.
Here's what mappings look like: