users@jaxb.java.net

Re: [jaxb2] Namespace and other questions

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 12 Apr 2007 11:45:24 -0700

Spies, Brennan wrote:
> 1) XmlAccessType.PROPERTY or XmlAccessType.PUBLIC_MEMBER give me errors
> complaining of duplicates...the runtime would complain that I had duplicates
> such as "location" and "getLocation()". Why? I had to switch to
> XmlAccessType.NONE and annotate each field member individually.

The error message should have gave you pointers to two offending
property definitions. For example, if you set it to PUBLIC_MEMBER and
both the location field and the getLocation() method is public, you'll
end up binding both.

You can put @XmlTransient on one of those to avoid the duplicate.

>
> 2) When marshalling to <websphere> or <remote-api> elements, JAXB would
> set the default namespace to null and then set that element to the namespace
> I had declared in the annotation, like
>
>
>
> <ns4:websphere xmlns="" xmlns:ns4="mynamespace">
>
>
>
> ..even though the default namespace for all of the DOM is "mynamespace".
> Playing around with "##default" didn't help.

This happens when some elements known to JAXBContext uses the empty
namespace. Most likely this is because you don't have
@XmlSchema(elementFormDefault=QUALIFIED)

I really regret this default, but the EG felt we should be consistent
with XML Schema, even if that means bug-to-bug consistent.


> 3) The behavior in #2 caused all of the child elements of <websphere> or
> <remote-api> to have null namespaces. I had to manually set the 'namespace'
> attribute on the individual @XmlElement annotations in order to set the
> namespace correctly. Is there a way to simply do this at the class level?

See above.

> 4) I am not able to customize the namespace prefix using a custom
> NamespacePrefixMapper class (following the example under /examples in the
> distro). It generates "ns4" every time...

Take a look at a sample bundled in the RI.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com