users@jaxb.java.net

Re: XmlJavaTypeAdapter issue

From: Dan Diephouse <dan_at_envoisolutions.com>
Date: Wed, 27 Sep 2006 22:03:17 -0400

Hiya,

Here is an example where the names have been changed to protect the
innocent:

package com.acme.model;

@XmlType(name="Customer")
public class CustomerImpl {
private String name;
public String getName() {...}
public void setName(String n);
}

I call:

JAXBElement jel =new JAXBElement(new QName("http://ws.acme.com",
"SomeCustomer"));
marshaller.marshal(jel, outputStream);

I expect this:

<SomeCustomer xmlns="http://ws.acme.com">
  <name xmlns="http://model.acme.com">..</name>
</SomeCustomer>

I get this:

<SomeCustomer xmlns="http://ws.acme.com">
  <name>..</name>
</SomeCustomer>

JAXB should use the namespace from the package on the <name> element, right?

- Dan

Kohsuke Kawaguchi wrote:
> Dan Diephouse wrote:
>> Hiya,
>>
>> I'm trying to get my XmlJavaTypeAdapter on an interface to work with
>> the code first approach. I'm wondering, should I be specifying the
>> interface or type class to jaxb. Let me try to explain the two
>> areas... I have an interface Customer and an implementation
>> CustomerImpl. In my jaxb.index - should I put Customer there or
>> CustomerImpl?
>
> CustomerImpl.
>
>
> > Also when I do:
>>
>> new JAXBElement(qname, class, object);
>>
>> Should my class be Customer or CustomerImpl?
>
> CustomerImpl.
>
>> I tried Customer but JAXB complains that its an interface. I tried
>> CustomerImpl, but JAXB is serializing it wrong - its using the
>> namespace from the qname on all the child elements (i.e.
>> customer.name, customeraddress) instead of using the package
>> generated namespace.
>
> When you marshal out a JAXBElement, it should always take the tag name
> from the first QName parameter that you pass to JAXBElement, never
> from the class.
>
> Can you show me your CustomerImpl class definition, package-info.java,
> and the infoset that JAXB generated?
>


-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com
http://netzooid.com/blog