[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] MOXy/JAXB question regarding package-info
|
@XmlJavaTypeAdapter annotations can be used to specify
XmlAdapter instances that can be used to map non-bindable classes to bindable JAXB classes. What's even more convenient is that these annotations can be applied at the package level by placing them on the
package-info.java file. My question concerns: which
package-info.java file does MOXy/JAXB consult, and how does it know which
package-info.class files to hunt through for such annotations?
More precisely: Given an
@XmlJavaTypeAdapter annotation found (somehow) on a
package-info class (inside a wrapping
@XmlJavaTypeAdapters annotation) with a correctly-specified
type() attribute, is there any requirement that the type so specified in the annotation belong to the same package that is being annotated?
In other words, is this valid:
// package-info.java for com.whizbang.whatever:
@XmlJavaTypeAdapters({
@XmlJavaTypeAdapter(type = com.foobar.bozo.Type.class,
value = com.fizbaw.adapters.SomeXmlAdapterSubclass.class)
})
package com.whizbang.whatever; // look; it's not com.foobar.bozo
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
// end package-info.java
...?
Note that the package being annotated is
com.whizbang.whatever, the package of the class specified as the
@XmlJavaTypeAdapter's
type() attribute is
com.foobar.bozo, and the adapter class package (probably irrelevantly) is
com.fizbaw.adapters.
I'm curious how JAXB implementations like MOXy go about locating this
package-info to find the potential list of adapted classes. I could see two conceptual approaches:
- Some sort of scanning for package-info.class resources. I'm guessing this is not what happens?
- "Backing into" the package: JAXB encounters an object that needs to be marshaled, discovers it's not in the JAXBContext of the moment, and so investigates its package (Class#getPackage()) to see if that package has any helpful adapter annotations on it. In this case, it would be an effective requirement that an @XmlJavaTypeAdapter annotation applied to a package-info.java file would need to specify a Class for its type() attribute that belonged to the same package as the one being annotated.
My larger context is that I'd like to simply have a package somewhere on the classpath--call it
com.foobar.adapters--that has a
package-info.java on it that "hosts" all known
XmlJavaTypeAdapters for my enterprise application. Some of these govern types that would obviously not be part of the
com.foobar.adapters package. I haven't yet tried this but I would think this might pose a problem.
This is obviously quite hard to articulate; I hope I've been clear in my questions. Thanks for any help!
Best,
Laird
--
http://about.me/lairdnelson