Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic return object for a collection of objects in RESTful Spring3 app

I am looking for a generic way of returning a set of objects in my REST service. I use the Spring3 message-converters and the @ResponseBody annotation.

Some sites say that JAXB2 has "problems" returning a standard java.util.List, and all examples found define a dedicated class (e.g. Authors, Products, Customers) for each data domain, such as:

http://www.ibm.com/developerworks/web/library/wa-spring3webserv/index.html (see "Collection of resources", second paragraph)

Has anyone found a way to provide a generic class/approach for this that spares me creating all those collection classes?

Update 5th April 2011: I haven't really made any progress on this. Returning a generic list object always results in a JAXBException "class XXX nor any of its super class is known to this context"

like image 672
Tom Avatar asked Nov 29 '10 15:11

Tom


1 Answers

When creating REST services in a JAX-RS framework (which uses JAXB for XML binding) you can return a List. For an example see:

  • http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-45.html

What happens when you try to do this with Spring?

like image 134
bdoughan Avatar answered Oct 21 '22 18:10

bdoughan