I need to return to client list of few results and total count of results. I have to do it on several places with different entities so I would like to have a generic class with these two attributes:
@XmlRootElement
public class QueryResult<T> implements Serializable {
private int count;
private List<T> result;
public QueryResult() {
}
public void setCount(int count) {
this.count = count;
}
public void setResult(List<T> result) {
this.result = result;
}
public int getCount() {
return count;
}
public List<T> getResult() {
return result;
}
}
And the service:
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public QueryResult<TestEntity> findAll(
QueryResult<TestEntity> findAll = facade.findAllWithCount();
return findAll;
}
Entity is not important:
@XmlRootElement
public class TestEntity implements Serializable {
...
}
But this causes: javax.xml.bind.JAXBException: class test.TestEntity nor any of its super class is known to this context.
Returning of just collection is easy but I don't know how to return my own generic type. I tried to use GenericType
but without success - I think it's ment for collections.