在 Web 服务中返回 java.util.List
我尝试在 eclipse 中创建一个自下而上的 Java bean Web 服务,我需要返回一个 java.util.List,所以我在服务器上有这个
public class BookStoreWS {
private Book book1;
private List<Book> listOfBooks;
public Book getBook(){
return book1;
}
public List<Book> getBooks(){
return listOfBooks;
}
}
,在客户端上有这个
public static void main(String[] args) {
BookStoreWSStub stub = new BookStoreWSStub();
GetBookResponseDocument gbrd = stub.getBook();
Book book = gbrd.getGetBookResponse().getReturn();//OK
GetBooksResponseDocument gbrd2 = stub.getBooks();
XmlObject OMGIAMNOTALIST = gbrd2.getGetBooksResponse().getReturn();//BAD
}
,所以 getBook() 返回我想要的对象 Book
但 getBooks()
返回 XmlObject
而不是 List
任何简单的方法可以获得List
而不是 XmlObject
?或者将 XmlObject
转换为 List
?
I try to create a Bottom up Java bean Web Service in eclipse and I need to return a java.util.List
so I have this on the server
public class BookStoreWS {
private Book book1;
private List<Book> listOfBooks;
public Book getBook(){
return book1;
}
public List<Book> getBooks(){
return listOfBooks;
}
}
and this on the client
public static void main(String[] args) {
BookStoreWSStub stub = new BookStoreWSStub();
GetBookResponseDocument gbrd = stub.getBook();
Book book = gbrd.getGetBookResponse().getReturn();//OK
GetBooksResponseDocument gbrd2 = stub.getBooks();
XmlObject OMGIAMNOTALIST = gbrd2.getGetBooksResponse().getReturn();//BAD
}
So getBook()
returns my desired object Book
but getBooks()
returns XmlObject
instead of a List<Book>
Any easy way of getting a List<Book>
instead of a XmlObject
? Or to transform the XmlObject
into a List<Book>
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是您要找的吗?
XmlObject
(很可能)不能是 A,但 item 肯定是。Is that what you are looking for?
XmlObject
(most probably) cannot be an A, but item surely is.