wsgen:返回一个抽象类
我编写了一个抽象类
import javax.xml.bind.annotation.*;
public abstract class Parent
{
@XmlAttribute(name = "one")
public String getOne() { return "one";}
}
和两个派生类:
import javax.xml.bind.annotation.*;
@XmlRootElement(name="child1")
public class Child1 extends Parent
{
@XmlAttribute(name = "two")
public String getTwo() { return "2";}
}
import javax.xml.bind.annotation.*;
@XmlRootElement(name="child2")
public class Child2 extends Parent
{
@XmlAttribute(name = "three")
public String getThree() { return "3";}
}
以及一个 @webservice:
import javax.xml.ws.Endpoint;
import javax.jws.*;
import java.util.*;
@WebService(serviceName="MyServerService", name="MyServer")
public class MyServer
{
private int count=0;
@WebResult(name="test")
@WebMethod
public Parent getOne() { return ++count%2==0?new Child1():new Child2();}
public static void main(String[] args) {
Endpoint.publish(
"http://localhost:8080/path",
new MyServer());
}
}
当使用 wsgen 生成代码时,生成的 XML 模式仅包含抽象类 Parent 的定义但不适用于 Child1 或 Child2。有没有办法告诉 wsgen 生成两个具体类的定义?
谢谢,
I wrote an abstract class
import javax.xml.bind.annotation.*;
public abstract class Parent
{
@XmlAttribute(name = "one")
public String getOne() { return "one";}
}
and two derived classes:
import javax.xml.bind.annotation.*;
@XmlRootElement(name="child1")
public class Child1 extends Parent
{
@XmlAttribute(name = "two")
public String getTwo() { return "2";}
}
import javax.xml.bind.annotation.*;
@XmlRootElement(name="child2")
public class Child2 extends Parent
{
@XmlAttribute(name = "three")
public String getThree() { return "3";}
}
and a @webservice:
import javax.xml.ws.Endpoint;
import javax.jws.*;
import java.util.*;
@WebService(serviceName="MyServerService", name="MyServer")
public class MyServer
{
private int count=0;
@WebResult(name="test")
@WebMethod
public Parent getOne() { return ++count%2==0?new Child1():new Child2();}
public static void main(String[] args) {
Endpoint.publish(
"http://localhost:8080/path",
new MyServer());
}
}
When the code is generated using wsgen, the resulting XML schema only contains the definition for the abstract class Parent but not for Child1 or Child2. Is there any way to tell wsgen to generate the definition for the two concrete classes ?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加注释
@XmlSeeAlso
应该可以解决问题:如果您不想让父类了解其子类,您也可以将该注释放在 WS 级别:
有关此行为的有趣信息,您可以找到 < a href="https://blogs.oracle.com/enterprisetechtips/entry/using_type_substitution_with_web" rel="nofollow">此处
Adding an annotation
@XmlSeeAlso
should do the trick:If you prefer not to make parent class aware of its subclasses you can put that annotation on the WS level as well:
Interesting information about this behavior you can find here