I had exactly the same problem. The problem is due to erasure of the Java type.
My first approach was to create a result class for each entity type:
public class Entity1Result extends QueryResult<Entity1> { ... } public class Entity2Result extends QueryResult<Entity2> { ... }
I returned a generic QueryResult<> in my settings for built-in types only, such as QueryResult<String> or QueryResult<Integer>
But it was cumbersome because I had many entities. So my other approach was to use only JSON, and I changed my class of results to non-generic and used the result field of Object :
public class QueryResult { private Object result; }
It works great, Jersey is able to serialize everything that I give it in JSON (Note: I do not know if this is important, but QueryResult and all my entities still have @Xml... annotations @Xml... for lists with their own entity types.
If you have problems with collections, you can also see this question.
hage Jun 06 '12 at 7:19 2012-06-06 07:19
source share