Reputation: 1
How do I set up an annotation for attributes in a SOAP request? My example:
public class Example {
@WebMethod()
public void test(@WebParam(name="pingRequest")PingRequest HotelPingRQ) {}
}
public class PingRequest
{
private String echo;
public String getEcho() {
return echo;
}
public void setEcho(String echo) {
this.echo = echo;
}
}
If I generate a WSDL and put it into SoapUI I get this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:door="http://www.test.com/doorway">
<soapenv:Header/>
<soapenv:Body>
<door:test>
<pingRequest>
<!--Optional:-->
<echo>?</echo>
</pingRequest>
</door:test>
</soapenv:Body>
but I want something more like the following, with echo
as an attribute and no test element:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:door="http://www.test.com/doorway">
<soapenv:Header/>
<soapenv:Body>
<pingRequest echo="?" />
</soapenv:Body>
How can I convert the echo
parameter to an attribute on pingRequest
instead of a nested element?
Upvotes: 0
Views: 329
Reputation: 2664
Try this:
@XmlAccessorType(XmlAccessType.FIELD)
public class PingRequest
{
@XmlAttribute
private String echo;
public String getEcho() {
return echo;
}
public void setEcho(String echo) {
this.echo = echo;
}
}
Upvotes: 1