import java.util.List; public class Employee { private int age; private String name; private List<String> addresses; public Employee() { } public Employee(int age, String name, List<String> addresses) { super(); this.age = age; this.name = name; this.addresses = addresses; } //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() + " - " e.getAddresses); return e; }As a result of generating the client using wsimport, the generated Employee looks like:
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "employee", propOrder = { "addresses", "age", "name" }) public class Employee { @XmlElement(nillable = true) protected List addresses; protected int age; protected String name; }
and strangely enough there is no setter method for the list of addresses. There is a clear explanation for the same in the comments above the getter for the addresses property as:
This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. This is why there is not a <CODE>set</CODE> method for the addresses property.
Solution: But this doesn't mean that this is a dead end. As mentioned in the original blog, you can replace the generated Employee class with the one that you used in the Web Service. With that you shall have the setter method for addresses list and the client invokes the Web Service perfectly.