Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 3 JSON with MVC

Is there a way to build Spring Web calls that consume and produce application/json formatted requests and responses respectively?

Maybe this isn't Spring MVC, I'm not sure. I'm looking for Spring libraries that behave in a similar fashion to Jersey/JSON. The best case would be if there was an annotation that I could add to the Controller classes that would turn them into JSON service calls.

A tutorial showing how to build Spring Web Services with JSON would be great.


EDIT: I'm looking for an annotation based approach (similar to Jersey).

EDIT2: Like Jersey, I am looking for REST support (POST,GET,DELETE,PUT).

EDIT3: Most preferably, this will be the pom.xml entries and some information on using the spring-js with jackson Spring native version of things.

like image 296
stevedbrown Avatar asked Oct 21 '09 16:10

stevedbrown


4 Answers

In case other ppl get here later: http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/ was the most useful link for me. That finally made me understand the model (after less than a day of searching).

like image 172
Johan Avatar answered Oct 27 '22 09:10

Johan


You can certainly have controllers that return a View which is in JSON output. Take a look at the Spring-JSON project.

To consume requests in JSON I would assume you would just want a controller to pass a request parameter off to a JSON library which could parse the data?

like image 26
matt b Avatar answered Oct 27 '22 08:10

matt b


There is no pre-packaged way to do what you want as Jersey is nicely integrated with Spring via the Jersey-Spring API so there's really no reason to re-invent the wheel.

like image 4
non sequitor Avatar answered Oct 27 '22 08:10

non sequitor


Check this one out

Adding support for JSON and XML views

Source code for Spring Finance Manager

like image 3
jitter Avatar answered Oct 27 '22 08:10

jitter