Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to write web-service that returns a collection of generic type? Spring 3
    primarykey
    data
    text
    <p>In my db I have a number of entity classes and I run standart CRUD operations on them via Hibernate. Its not a problem to create generic dao class to make all main operations with classes. For example, in dao I have methods which look like this:</p> <pre><code>&lt;T&gt; List&lt;T&gt; loadAll(Class clazz) </code></pre> <p>Now I want to expose these methods to web-service client via Spring 3 operated web-service.</p> <p>The only way I see is to implement web-methods for all entities i.e. write a class that looks like... </p> <pre><code>class BookResponse { List&lt;BookEntity&gt; books; } </code></pre> <p>... and return this in corresponding web-method "BookResponse getAllBooks()". This will ruin my attemts to make a code simplier by using dao with generics. </p> <p>Is there are any other ways? How can I do this without implementing web-methods for ALL my entities? If generic web-service is not possible may be there are some other ways to resolve this task in a simple way?</p> <p>UPDATE: At the moment I am trying to implement a response class which should look like</p> <pre><code>public class ServiceResponse&lt;T&gt;{ @XmlElementWrapper( name = "data" ) @XmlElements( @XmlElement(name = "a", type = EntityA.class), @XmlElement(name = "b", type = EntityB.class) ) private List&lt;T&gt; data = new ArrayList&lt;T&gt;( ); //getters,setters } </code></pre> <p>So I want to be able to insert a list of any entities mapped with annotations to this response. This produces no erros, but the response given me by web-service is empty.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload