Sambuddha
Sambuddha

Reputation: 245

Add an extra tag or element in Soap Response using Jaxws

I am developing one soap service using Spring-Cxf. here I have my response structure as below

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "response", propOrder = {
    "name",
    "addressList"
})
public class Response 
{

private String name;
private List<Address> addressList;
}

-- getter and setter follows

The current response is coming like

<response>
   <name>RASSI ANDREA</name>
   <addressList type="1">
      <address>Address 1</address>
      <address>Address 2</address>
      <address>Address 3</address>
   </addressList>
   <addressList type="2">
      <address>Address 4</address>
      <address>Address 5</address>
      <address>Address 6</address>
   </addressList>
</response>

But the actual response structure I need is below where a new tag 'row' is added.

<response>
   <name>RASSI ANDREA</name>
   <row>
      <addressList type="1">
         <address>Address 1</address>
         <address>Address 2</address>
         <address>Address 3</address>
      </addressList>
   </row>
   <row>
      <addressList type="2">
         <address>Address 4</address>
         <address>Address 5</address>
         <address>Address 6</address>
      </addressList>
   </row>
</response>

Can anyone explain me where should I make the change to achieve this ? Any change in annotation or Creating a new class as 'row'( though this will a bad approach I guess)

Upvotes: 0

Views: 1824

Answers (1)

anacron
anacron

Reputation: 6721

Adding the Annotation @XmlElementWrapper(name="row") to your addressList will add the <row> tag to your XML. Give it a try.

You will need to add the following statement:

import javax.xml.bind.annotation.XmlElementWrapper;

public class Response {

    private String name;
    @XmlElementWrapper(name="row") // Add this line here
    private List<Address> addressList;
}

Upvotes: 2

Related Questions