users@jaxb.java.net

RE: RE: Mapping of java objects with XSD using JAXB

From: Deepa Sobhana <Deepa.Sobhana_at_ust-global.com>
Date: Thu, 5 Jun 2008 17:30:51 +0530

Thanks Ted for the reply. But my problem is something different. If I use XJC to generate the JAXB objects, I have to get the value of username as person.getContacts().getContactDetails() and then iterate the contact details list to get usernames list. In order to simplify this kind of data access, I am wondering if I can add a new property in my Person POJO class (manually written, not generated using XJC) and then map it to username tag directly like <person>/<contacts>/<contactdetails>/<username>...... I have read that @XmlElement(name = "some tag name") annotation can be used to map a property with an XML tag, but how do i specify the name of a child tag here. Is this possible in JAXB?
 
Thanks,
Deepa.

________________________________

From: Ted Poovey [mailto:tpoovey_at_uscentral.org]
Sent: Thu 6/5/2008 12:03 AM
To: users_at_jaxb.dev.java.net
Subject: RE: Mapping of java objects with XSD using JAXB



Well first of all you need to modify the XSD to have username occurs x to maximum unbounded or some such times. Then the XJC will generate class with appropriate List<String> getter method.

 

Thank you

 

Ted Poovey

Software Engineer III

I.T. Application Management

U.S. Central

9701 Renner Blvd

Lenexa, KS 66219

(ph) 913-227-6106

(fax) 913-227-6254

 

________________________________

From: Deepa Sobhana [mailto:Deepa.Sobhana_at_ust-global.com]
Sent: Wednesday, June 04, 2008 1:08 PM
To: users_at_jaxb.dev.java.net
Subject: Mapping of java objects with XSD using JAXB

 

Hi,

 

I have a query regarding the mapping of java objects with XSD using JAXB. I have a sample XML like this

<person>
    <personname>Joe</personname>
 <age>20</age>
    <contacts>
     <contactDetails>
      <username>Smith</username>
      <address>US</address>
     </contactDetails>
     <contactDetails>
      <username>Bill</username>
      <address>Canada</address>
     </contactDetails>
    </contacts>
</person>

 

In order to easily access the list of usernames(<username>), I would like to add a new property ( List<String> userNames ) in Person class. How do I map this property with <person>/<contacts>/<username>.Is this possible using JAXB? Any help in this regard would be appreciated.

 

Thanks,
Deepa