Suppose you have a Web Service with a Web Method that takes and returns a POJO of Class Employee:-
public class Employee {
private int age;
private String name;
public Employee() {
}
public Employee(int age, String name) {
super();
this.age = age;
this.name = name;
}
//write getter setter for properties to comply to Java Bean/POJO standard
}
and the Web Method is:
@WebMethod
public Employee printEmployee(Employee e) {
System.out.println(e.getName() + " - " + e.getAge());
return e;
}
On generating the client, an Employee POJO is automatically generated but with some XML stuff and no constructor i.e. default constructor:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "employee", propOrder = {"age", "name"})
public class Employee {
protected int age;
protected String name;
// Setters and Getters for the properties are also generated
}
There seems to be two things about this generated POJO that irritates me:
- The newly generated Employee POJO has a lot of XML stuff that does not do any work in service invocation.
- I miss the constructor that takes in values for the POJO i.e. new Employee("name", 23);
No comments:
Post a Comment