Wrote a simple webservice with CXF.
The model is as follows:
public class ProductModel implements Icachable, Serializable {...}
public class Invelinkmodel extends ProductModel {...}
The WebService interface is defined as follows
Public interface Iproductcenter {
Public ProductModel seekpinfo (String pid);
}
A client was acquired with spring injection. The XML configuration for spring is as follows:
<jaxws:client id= "pcenterclient" address= "" serviceclass= "xxx"/>
The client code is as follows:
Iproductcenter client;
There's a problem here.
ProductModel Product = Client.seekpinfo ("eli_cw_001");
The problem is that the model that the client obtains is always an instance of ProductModel, regardless of whether the WebService service-side implementation class returns Invelinkmodel or ProductModel.
The workaround is simple:
Import javax.xml.bind.annotation.XmlSeeAlso;
@XmlSeeAlso (value = {Invelinkmodel.class})
public class ProductModel implements Icachable, Serializable {}
The xmlseealso annotation declares a subclass of this class. The WebService server is serialized and deserialized based on the value of this annotation and the actual type of model, allowing the client to obtain the correct type required.
WebService returning subclasses