views:

490

answers:

5

I wish to use Spring MVC to provide a REST web service. However, running through some books and tutorials, it looks like ModelAndView always returns a parsed JSP file. I guess I could make the JSP build my XML document, but is this the best way to go about things? I thought that perhaps a more structured XML building approach might be appropriate.

What are my options? Also, does anyone have any relevant tutorials?

+2  A: 

This would probably help somewhat. It seems you are looking for a Marshalling View.

Alternatively, a JAX-RS implementation like Jersey or RESTeasy might suit you as well.

Drew
+1  A: 

Have you considered integrating Spring with RESTlet library? This page might be a good starting point...

Ivan Vrtarić
+1  A: 

The View part of ModelAndView does not have to represent a JSP.

See chapter 17 of the reference manual, for example in chapter 17.5 they describe how to set up a XSLT view (not what you need, but shows how different views are supported).

http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch17s05.html

Dick Chesterwood
+1. Neato. I wound up just using XOM to manually build XML, but I'll not this for future projects.
Stefan Kendall
A: 

There are a number of options for marshaling java beans into either XML or JSON. I use the spring-json package for rendering my model into JSON for my web service, and there are several choices if you want to render XML instead.

A: 

You could check out Freemarker. Basically, XML is just text, and by using a templating system you could easily create your XML document that you want to return.

igotmumps