Re: users Digest 22 Jul 2008 11:20:05 -0000 Issue 175

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: users Digest 22 Jul 2008 11:20:05 -0000 Issue 175

Tim McCune-3

From: Jakub Podlesak <[hidden email]>
To: [hidden email]
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());

Loading...