Skip to content
Ryan Heaton edited this page Sep 17, 2015 · 1 revision

Note: The following only applies to Enunciate 1.x. Enunciate 2 provides more support for JAX-RS lists.

Lists and JAX-RS

Often you want to return a list of objects from a resource method:

@Path("/things")
public class ThingsResource {
 @GET
 List<Thing> getThings();
}

Enunciate won't know how to document the response body for this resource method, calling the response body a "custom" element.

That's because JAX-RS doesn't specify how to serialize Lists (or any instance of Collection for that matter). Most implementations of JAX-RS (e.g. Jersey, CXF, Resteasy) support a list in the response, but because JAX-RS doesn't fully specify what it should look like, each implementation might do it differently. So Enunciate has to punt and call it a "custom" element.

The workaround is to provide a "wrapper" class:

@XmlRootElement
public class Things {
 public List<Thing> things;
}

And return the wrapper class instead of the list:

@Path("/things")
public class ThingsResource {
 @GET
 Things getThings();
}
Clone this wiki locally