Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get structred XML Response in Webservice

 
thilsen kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
thilsen kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , i solved tat.. thanks for your reply.

Thilsen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic