users@jersey.java.net

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

From: Owen Jacobson <owen.jacobson_at_grimoire.ca>
Date: Fri, 17 Jan 2014 11:12:44 -0500

Is there a good way to obtain the JAXBContext that Jersey creates, inside my custom ContextResolver<Marshaller>?

-o

On Jan 17, 2014, at 3:53, Jakub Podlesak <jakub.podlesak_at_oracle.com> wrote:

> Hi Owen,
>
> You can use the same principle as for the JAXBContext resolver,
> i.e. you can also implement your own custom Marshaller resolver provider,
> ContextResolver<Marshaller>, that Jersey will use internally to create
> JAXB marshaller.
>
> HTH,
>
> ~Jakub
>
> On 17 Jan 2014, at 04:40, Owen Jacobson <owen.jacobson_at_grimoire.ca> wrote:
>
>> 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
>>
>