The following is help.
EXPLANATIONS
JAXB class classes do not require annotations. There is no annotation indicating that the class should be automatically processed when creating the JAXBContext .
CREATING A JAXBContext
There are two main ways to create a JAXBContext
1 - In the classes
You are passing an array of domain classes. Then, mappings are created for these classes. Mappings are also created for references (see WHAT CLASSES A BROUGHT IN below).
2 - Context paths
In my article you pointed out ( http://blog.bdoughan.com/2010/08/using-xmlanyelement-to-build-generic.html ), the context path is used. The context path consists of colon-delimited package names. Each package must contain either a jaxb.index file or an ObjectFactory . The jaxb.index file is a separate list of class names that you want to create JAXBContext . Just as when creating a JAXBContext in an array of classes, reference classes are also processed.
WHAT CLASSES TO VIEW
The following are some key concepts related to which secondary classes are processed when creating a JAXBContext .
1 - Related classes
If a JAXBContext is created in the Foo class, then Bar will also be processed because it is referenced by Foo .
@XmlAccessorType(XmlAccessType.FIELD) public class Foo { private List<Bar> bar; }
2 - Superclasses
If a class is being processed, its superclass is also being processed. You can put the @XmlTransient annotation in a class to prevent it from being processed (see http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html ).
public class Foo extends Bar { }
3 - Subclasses
If a class is processed, then its subclasses are not processed automatically. You can put the @XmlSeeAlso annotation in a class to indicate its subclasses that you want to process.
@XmlSeeAlso({Bar.class}) public class Foo { }
4 - Classes related to JAXB annotations
If a class is being processed, then the classes specified in the JAXB annotations inside this class are also processed
public class Foo { @XmlElements({ @XmlElement(name="a", type=A.class), @XmlElement(name="b", type=B.class) }) private Object bar; }