I write web services using jax-ws, and wsdl contains many types. Java classes for XML mapps using jaxb. Consider the following example:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Person")
public class Person {
@XmlElement(name = "firstName")
protected String firstName;
@XmlElement(name = "lastName")
protected String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String value) {
this.firstName = value;
}
public String getLastName() {
return lastName;
}
public void setLastName(String value) {
this.lastName = value;
}
}
So, we have the XML type Person, which is included in the WSDL. We can call this class an interface (for web service clients). Server code can have a set of derived classes. For instance,
public class EmployeePerson extends Person {
protected String post;
}
public class ClientPerson extends Person {
}
The web service operation returns an object of type Person:
@WebMethod(operationName = "GETPERSON")
public Person getPerson(@WebParam(name = "ID") String personId);
In fact, we can return one of the derived types, but the XML type "Person" must be returned to the client ( xsi:type='ns:Person'). If we use @XmlTransient, an object of type undefined will be returned. How can we superimpose a derived class on a base type?
source
share