jax-ws中映射多态

public interface AnimalService {
    @WebMethod
    void add(Animal animal);
}

这里Animal是抽象类,它有两个子类Cat和Dog; 有没有办法在WSDL里实现这种多态?

答案是可以,使用@XmlSeeAlso注解即可

@XmlSeeAlso({Cat.class, Dog.class})
public abstract class Animal{
} 

这样产生的WSDL里会有这样的东西:

<xs:complexType name="cat">
<xs:complexContent>
<xs:extension base="tns:animal">
<xs:sequence>
...
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.