users@jersey.java.net

[Jersey] Re: How to move namespace declarations up to the root element?

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Fri, 13 May 2011 10:25:40 +0200

Are you marshalling List of something? If so, there is not much what can
help, AFAIK JAXB doesn't have something like namespace mapper (namespace
prefix mapper is different thing) and Jersey marshalls list entrys one
by one without any transferred context using Marshaller.JAXB_FRAGMENT
(and that is what causes multiple namespace declaration).

If its just a simple element, JAXB should be able to do this for you,
but depends on your schema and elements you use. If you use xsd:any and
similar not predictable content, output will be always polluted with
namespace declarations (JAXB would need to do 2-pass run to get rid of
these..)

Pavel

On 5/12/11 12:39 PM, Markus Karg wrote:
>
> I'm not a JAXB guru so I need to ask silly questions like the
> following...:
>
> JAX-RS is marshalling the resulting entity for a request internally,
> what is a great feature. In my case, the XML output contains lots of
> namespaces, and most of them repeat again and again. So I'd like to
> "pull up" the prefix declarations to the root node.
>
> Does anybody know how to solve that from within a JAX-RS resource? As
> I am using a custom ContextResolver anyways I could tweak the
> JAXBContext if that is need.
>
> Thanks!
>
> Markus
>