users@jaxb.java.net

Marshalling from _at_XmlJavaTypeAdapter for Map type emits redundant or duplicated namespaces

From: KARR, DAVID (ATTSI) <"KARR,>
Date: Tue, 15 Mar 2011 08:23:05 -0700

I'm using CXF with classes defined with JAXB annotations.

All of my JAXB-annotated classes are in a single package, along with a
package-info.java file.

In general, the XML and schema rendered from these annotations is fine.
However, I've been struggling with two Map attributes. As JAXB can't
render Maps on its own, I'm using @XmlJavaTypeAdapter to map my HashMap
type to an adapter.

My first attempt at getting the schema excerpt for the Map that I wanted
didn't work, for unexplained reasons (JAXB fails deep within with a
NPE), but I was able to find a more conventional structure which works
well enough. I discussed this problem on a different thread.

Now I'm trying to do a little cleanup. Currently, the Map is rendering
like this:

                <entries>
                  <entry>
                    <key
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">g</key>
                    <value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:type="xs:string">h</value>
                  </entry>
                  <entry>
                    <key
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">e</key>
                    <value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:type="xs:string">f</value>
                  </entry>
                </entries>

It puts those namespaces on every key and value it renders. No other
elements besides the root element have namespace definitions. I'd
prefer to have those namespace definitions appear on the root element.
I've already tried defining these namespaces in @XmlNs annotations
inside the @XmlSchema annotation in the package-info.java file, but that
doesn't fix this.