I created a sample jax-ws project in my eclipse.
below is the code that has an interface, an Imp class and an assistant class
Interface:
@WebService
public interface HelloWorld
{
@WebMethod(operationName="getString")
@WebResult(name="Result")
Helper getHelloWorldAsString(@WebParam(name="input")String str);
}
Implementation:
@WebService(endpointInterface = "com.test.HelloWorld")
public class HelloWorldImpl implements HelloWorld
{
@Override
public Helper getHelloWorldAsString(String str) {
Helper h = new Helper();
String[] str1 = {"ABC", "DEF", "GHI"};
h.setTempValue(str1);
return h;
}
}
Assistant:
@XmlRootElement(name = "TypeCode")
@XmlType(name = "TypeCode")
@XmlAccessorType(XmlAccessType.FIELD)
public class Helper
{
@XmlElement(name="value")
private String[] tempValue;
public String[] getTempValue() {
return tempValue;
}
public void setTempValue(String[] tempValue) {
this.tempValue = tempValue;
}
}
When I deploy the code above and submit the request, I see the answer as shown below:
<ns2:getStringResponse xmlns:ns2="http://test.com/">
<Result>
<value>ABC</value>
<value>DEF</value>
<value>GHI</value>
</Result>
</ns2:getStringResponse>
The above answer has a root element as "Result", but I declared @XmlRootElement(name = "TypeCode")in the Helper class. My question is why there is no βTypeCodeβ marking as the root element, and not βResultβ. Yak-ws ignores @XmlRootElementand comes with @WebResult?
source
share