Engineering Full Stack Apps with Java and JavaScript
In the previous lab we created the web service with an annotation @XmlType with attribute propOrder on top of Employee class to define order of field elements.
Please note that, to change the response tag name or anything on the top level you will have to use JAX-WS annotations like @WebResult annoatation on top of an exposed method. For example, to change the grouping element name from <return> to employee, add the annotation @WebResult(name = “”) on top of public List<Employee> getAllEmployees() as:
@WebResult(name="Employee")
public List<Employee> getAllEmployees() {
We will compare the results through some screen shots. I have removed the annotation and taken the screenshots without annotation to compare the difference. I have also added the screenshot with @WebResult annotation applied.
Annotation was applied on top of the Employee class:
import javax.xml.bind.annotation.XmlType;
@XmlType(propOrder={"empNumber", "empName", "age"})
public class Employee {
@WebResult annotation was applied on top of the exposed WebMethod in EmployeeManager web service class:
@WebResult(name="Employee")
public List<Employee> getAllEmployees() {
return this.empList;
}
These screens were generated using the glassfish tester.
SOAP Response without JAXB annotation
SOAP Response with JAXB XmlType annotation
SOAP Response with JAXB XmlType and JAX-WS WebResult annotations
I have not added much explanations here. Feel free to ask if you have any doubts.