I am afraid a couple of days with the following problem. I searched quite a bit for the answer, here in SO, on the mailing lists and the network as a whole, but could not find the answer to this specific question.
Setting up the problem area ...
I am using Jersey 1.16 inside Tomcat 7.
I created a simple JAX-RS resource that looks like this:
@Path("/") @Produces({ "application/xml", "text/plain" }) public class ExampleResource { @GET public List<Thing> getThings() { List<Thing> list = new ArrayList<>(); list.add(new Thing("a thing 1", "a thing description 1")); list.add(new Thing("a thing 2", "a thing description 2")); return list; } }
Thing is an annotated POJO JAXB similar to this
@XmlRootElement(name = "thing") public class Thing { private String name; private String description;
I also set up WadlGeneratorJAXBGrammarGenerator.class
And when I ask GET http://localhost:8092/rest , it works like a charm - a formatted collection of Thing is returned.
The automatically generated WADL http://localhost:8092/rest/application.wadl almost perfect, it looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <application xmlns="http://wadl.dev.java.net/2009/02"> <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 1.16 11/28/2012 02:09 PM" /> <grammars> <include href="application.wadl/xsd0.xsd"> <doc title="Generated" xml:lang="en" /> </include> </grammars> <resources base="http://localhost:8092/rest/"> <resource path="/"> <method id="getThings" name="GET"> <response> <ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="thing" mediaType="application/xml" /> <representation mediaType="text/plain" /> </response> </method> </resource> </resources> </application>
As I said, almost perfect, and that is the problem.
<ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="thing" mediaType="application/xml" />
WADL does not describe that /getThings returns a List<Thing> . Rather, it looks like this refers to a single Thing element in xsd0.xsd . Therefore, when I submit it, for example, wadl2java, it generates an untyped client. To get a List<Thing> , I need to manually encode it, something like
List<Thing> asXml = root().getAsXml(new GenericType<List<Thing>>(){});
Does anyone know if it is possible to have an automatic WADL creation that somehow indicates that this particular resource returns a List of resources of a certain type?
And I don't want to create an additional ThingList JAXB-annotated class and return it instead to the jersey resource.
Iβm almost there, creating a βperfectβ WADL, itβs just (hopefully) a little piece that Iβm missing ...
Thank you very much!