users@jersey.java.net

Re: [Jersey] Replacing XMLJAXBElementProvider

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 22 Jul 2008 11:34:24 +0200

Just fixing a small typo in line...

On Tue, Jul 22, 2008 at 10:34:12AM +0200, Jakub Podlesak wrote:
>
> 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.
>
> e.g. st. like:
>
> public final class YourJAXBContextWrapper extends JAXBContext {
>
>
> private final JAXBContext defaultContext;
>
> public JSONJAXBContext(Class... classes) throws JAXBException {
             ^^^^^^^^^^^^^^
this should be YourJAXBContextWrapper of course.

> this.defaultContext = JAXBContext.newInstance(classes); // or you can use the one from Jersey
> }
>
> @Override
> public Marshaller createMarshaller() throws JAXBException {
> Marshaller marshaller = defaultContext.createMarshaller();
> marhaller.setProperty("KEY","VAL");
> return marshaller;
> }
>
> // ... etc
>
> }
>
> The wrapper will be then returned by your custom JAXBContext resolver.
>
> 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.
>
> ~Jakub
>
> [1]http://blogs.sun.com/japod/entry/better_json_available_in_jersey
>
> On Mon, Jul 21, 2008 at 02:55:53PM -0700, Tim McCune wrote:
> > As a follow-up to my "how do I specify xml namespace prefixes" question, I'm
> > trying to provide my own XMLJAXBElementProvider that lets me set properties
> > on the Marshaller. I need to replace
> > com.sun.jersey.impl.provider.entity.XMLJAXBElementProvider with this
> > implementation. So far, the only way I've found to do this it to remove
> > META-INF/services/javax.ws.rs.ext.MessageBodyWriter from the jersey jar, so
> > that jersey will find my javax.ws.rs.ext.MessageBodyWriter file instead. Is
> > this the only way to do this? Seems like it should be possible to do
> > something like this without having to build a custom jar.
> >
> > Thanks.
> >
> > --Tim
>
> --
> http://blogs.sun.com/japod
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
http://blogs.sun.com/japod