Search code examples
jaxbcontextpath

One class in same package does not bind to JAXB context


Using JAXBContext.newInstance("com.jaxbgen") to bind classes in this package. And then use this context to create mashaller.

It's so strange that one entity class xxx in this package could not mashaller, and throw JAXBException nor any of its super class is known to this context. And the other works well.

I try to use JAXBContext.newInstance(xxx.class) to initial the context, it works well.

But I need to use package name to mashaller all classed in this package.

Could anyone help me on it?


Solution

  • When the package name is used to create a JAXBContext the JAXB impl does one of the following:

    • Looks for a class called ObjectFactory and then transitively pulls in all reference ed classes.
    • Looks for a text file called jaxb.index which contains a carriage return separated list of short class names (not package qualified). These classes and all referenced classes are the processed.