Reputation: 922
I was investigating object marshaling
and unMarshaling
using JAXB
. while noticed that there is two option of getting an instance of JAXBContext
.
JAXBContext context = JAXBContext.newInstance(ex.getClass());
JAXBContext context = JAXBContext.newInstance(ex.getClass().getPackage().getName());
For the second way, you have to provide jaxb.index
file, containing list of bean class names.
Maybe someone can explain, what is the difference between this two methods of getting JAXBContext
instance? Which is better to use and when?
Upvotes: 1
Views: 2558
Reputation: 43651
For the second way, you have to provide
jaxb.index
file, containing list of bean class names.
This is not correct. In JAXB2 this works without jaxb.index
as well, the classes are "recognized" via ObjectFactory
and @XmlSeeAlso
.
The usual approach is to use JAXBContext context = JAXBContext.newInstance("my.package:my.another.package);
as you normally want to consider all of the relevant classes and don't want to enumerate them explicitly.
Upvotes: 2