我尝试在eclipse中创建一个Bottom up Java bean Web Service,我需要返回一个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<Book>
获取List<Book>
代替XmlObject
的任何简单方法?或者将XmlObject
转换为List<Book>
?
答案 0 :(得分:0)
这就是你要找的东西吗?
List<A> OMGIAMALIST = new ArrayList<A>();
OMGIAMALIST.addAll(stub.getAs());
for ( A item : OMGIAMALIST ) {
XmlObject OMGIAMANITEM = item.getGetAsResponse().getReturn();
}
XmlObject
(最有可能)不能是A,但肯定是。