I’ve studied Blaise Doughan’s answer to a question on this subject but have a further question.
XmlJavaTypeAdapters lets you list a bunch of XmlJavaTypeAdapter annotations, each of which governs how a non-bindable type is mapped to a bindable type by JAXB.
You can use this annotation at the package level. When you do so, every XmlJavaTypeAdapter annotation needs its type() attribute fully specified.
There does not appear to be a requirement that the package that is being annotated have anything to do with the package of the non-bindable types being adapted. That is convenient and nice.
That, however, leads me to my next question: if there is no relationship between the annotated package and the package of the type being adapted, how does JAXB discover package-level XmlJavaTypeAdapters annotations? How, in other words, does it know which packages to consult for potential XmlJavaTypeAdapters annotations? May I make a random package in, say, a .jar file in my .ear file’s lib directory that contains a single, ginormous package-info class that is annotated with all the adapters for all of my non-bindable types?
When the JAXB runtime loads a JAXB-annotated class, it looks for a
package-info.javain the same package as that class, and checks that to look for package-level annotations. So whileXmlJavaTypeAdaptersdoesn’t have to reside in the same package as the “non-bindable” types, it does have to reside in the same package as the “bindable” types.For example, say I have a JAXB-annotated class
A, in packageX, which has a property of typeBin packageY. In order to bind theBproperty, let’s say a type adapter is required. That adapter can be specified inAitself, or it can be specified in thepackage-info.javain packageX. PackageYis pretty much arbitrary, and is of no interest to the JAXB runtime.I hope that makes sense.