> From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
> To: users_at_jersey.dev.java.net
> Date: Tue, 22 Jul 2008 10:34:12 +0200
> Subject: Re: [Jersey] Replacing XMLJAXBElementProvider
>
> Hi Tim,
>
> All you need is to provide a custom JAXBContext resolver.
> See [1] for details. Then you can implement a wrapper
> for the default JAXBContext, returning Marshaller with
> certain properties preset.
Took me a bit to wrap my head around that, but once I got all the pieces in
place, it just worked the first time I tried it! :) Thanks for the
suggestion.
I think, i need to provide a direct way to set custom properties
> on Marshaller/Unmarshaller without a need to implement a custom
> JAXBContext wrapper. For the time being i hope the above
> mentioned solution would work for you.
That would be very nice. Even nicer would be a mechanism that
auto-configures the JAXBContext with the right prefixes, instead of all of
this ns1, ns2, etc. junk. Here's what I'm doing:
Class pkgInfo = Class.forName(pkgName + ".package-info");
XmlSchema schema = (XmlSchema) pkgInfo.getAnnotation(XmlSchema.class);
for (XmlNs ns : schema.xmlns()) {
if (ns.namespaceURI() != null && ns.prefix() != null) {
PrefixMapper.register(ns.namespaceURI(), ns.prefix());
}
}
where PrefixMapper extends
com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper, and then on the
Marshaller:
marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
new PrefixMapper());