From looking through the archives, I am led to believe that it is a bad
idea--or perhaps an impossible idea--to have a Resource that generates a
parameterized type as one of the formats it @Produces.
So, for example, I have learned that one cannot declare a Resource like this
(typed from memory off the cuff so forgive syntax errors):
public class SomeResource<T extends SomeTypeAnnotatedWithJAXB> {
@GET
@Produces(MediaType.APPLICATION_XML)
public Collection<T> getStuff() {
// etc.
}
}
...because Jersey has no way of knowing what T might be, and hence has no
idea how to spit out appropriate XML. I gleaned most of this from
http://n2.nabble.com/JSON-not-serializable-for-generic-types-tp3541751p3552413.html
.
Is this assumption largely correct? I assume it's true of any parameterized
type, yes? And is true whether one uses JSON or application/xml?
Background: I was hoping to put together a generic DAO that could return
collections of things without having to create a new resource for every
object that I wanted DAO functionality for.
Thanks for any insight. In case you can't tell, I am brand new to JAX-RS,
and am looking for the right place to jump in; please feel free to direct me
to wherever I need to go. (I have to say as a point of note that the Jersey
samples all kind of surprised me: most that had anything to do with
collections of things seemed to create JSON arrays by hand. Is that really
the way to go?)
Best,
Laird