This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Services and the fly likes Get structred XML Response in Webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Get structred XML Response in Webservice" Watch "Get structred XML Response in Webservice" New topic
Author

Get structred XML Response in Webservice

thilsen kumar
Greenhorn

Joined: Jul 10, 2007
Posts: 13
Hi all,
I am using jersey webservices. (REST based calls).
i am getting xml response by using
@Produces(MediaType.APPLICATION_XML).

Here i have a class called BaseData (which annotated by @XmlRootElement)
and subresource class called MyMetaData(which annotated by @XmlRootElement)

here i am getting xml as (subresource with 2 address)

<BaseData>
<description>Desc1</description>
<MyMetaData>
<address>aaaaaaaaaa</address>
<address>bbbbbbbbbb</address>
<zipcode>111111</zipcode>
<zipcode>222222</zipcode>
<city>Chennai</city>
<city>Trichy</city>
</MyMetaData>
<name>Thilsen</name>
<age>28</age>
<title>Mr</title>
</BaseData>

But i need to get it as

<BaseData>
<description>Desc1</description>
<MyMetaData>
<MetaData>
<address>aaaaaaaaaa</address>
<zipcode>111111</zipcode>
<city>Chennai</city>
</MetaData>
<MetaData>
<address>bbbbbbbbbb</address>
<zipcode>222222</zipcode>
<city>Trichy</city>
</MetaData>
</MyMetaData>
<name>Thilsen</name>
<age>28</age>
<title>Mr</title>
</BaseData>

How can i achieve this?
Please suggest me!

Thanks & Regards,
Thilsen
Hetal Vora
Greenhorn

Joined: Feb 11, 2009
Posts: 12
Create a class say MetaData with three data members - city, zipcode and address.
In MyMetaData class, you need have a data member which would be an array of MetaData objects.
Hopefully that should solve your problem.


Thanks and Regards, Hetal
SCJP 1.5 100%
thilsen kumar
Greenhorn

Joined: Jul 10, 2007
Posts: 13
Yes , i solved tat.. thanks for your reply.

Thilsen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get structred XML Response in Webservice