Java – Return generic type in a WebService

genericsjavaweb services

I'm green hand in web-service. I wrote a generic class as a value holder like this:

public class SearchResult<T> {
    private List<T> resultSet;
}

Then I write a web-service method:

public SearchResult<Book> getSearchResult(){
    ...
}

When I was using maven-jaxws-plugin to generate client files, I found that the generic type information was gone. They looked like :

public class SearchResult {
   private List<Object> resultSet;
}

public SearchResult getSearchResult(){
    ...
}

My question here is, do the jaxws can keep such kind of generic type information? I tried List as return type, it does work.
Thanks in advance for your help.

Best Answer

If the client code is generated using anything but the source, it will likely not contain the generic information. Once code using generics is compiled, information about generics is lost due to type erasure.