users@jaxb.java.net

Re: [jaxb2] Namespace and other questions

From: Dmitri Colebatch <dim_at_colebatch.com>
Date: Wed, 4 Apr 2007 11:01:07 +1000

Hi Brennan,

> 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.

Are you generating these classes using xjc, or have you written them
by hand? Do you have any subclassing? My guess is that you've
written them by hand and subclassed another class that also has JAXB
annotations. Could you post some code?

> 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.
>
> 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?

You can do it with package level annotations, I'm not aware of a way
to do it at the class level (but would be happy to hear of any).

cheers,
dim