users@jersey.java.net

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

From: Markus Karg <karg_at_quipsy.de>
Date: Fri, 13 May 2011 10:29:47 +0200

Unfortunately we need to use xsd:any... :-(

 

I hoped that there might be a way to tell the JAXBContent that there are
some well known namespaces, so it would declare them right at the start
at the root element and not repeat the declaration at each occurence...
no need for second pass as I would provide the namespaces for what this
shall happen.

 

Thanks

Markus

 

From: Pavel Bucek [mailto:pavel.bucek_at_oracle.com]
Sent: Freitag, 13. Mai 2011 10:26
To: users_at_jersey.java.net
Subject: [Jersey] Re: How to move namespace declarations up to the root
element?

 

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