users@jersey.java.net

[Jersey] Customizing the JAXB XML declaration as unintrusively as possible

From: Owen Jacobson <owen.jacobson_at_grimoire.ca>
Date: Thu, 16 Jan 2014 22:40:51 -0500

Hi there,

I’d like to suppress the XML declaration generated by JAXB in XML documents generated by my Jersey 2.5 application. It seems like this means I need to set the “jaxb.fragment” property on the JAXB Marshaller… but Jersey doesn’t give me any obvious ways to manipulate Marshallers it creates. I’d like to do this without intruding too deeply into Jersey’s provider mechanism, since JAXB and Jersey are both rather complex pieces of machinery.

In decreasing order of perceived intrusiveness, can I

1. insert some code between the point where Jersey creates a Marshaller and where it uses it to serialize objects?
2. write a provider for Marshaller that uses the Jersey-created JAXBContext, so that I can configure it without having to configure the entire JAXB setup?
3. something else I’ve not considered?

I’ve found a number of examples for Jersey 2 that create the whole JAXBContext, but the “jaxb.fragment” property must be set on individual Marshallers, not on the JAXBContext itself.

-o