This tutorial will walk through how to configure Spring MVC to return a JSON object to client browser.
How to do it?
You can use json-lib-ext-spring. There is other libs, but in my opinion, this is the simplest to use.
Do not forget to download Json-lib and its dependencies.
Now you have to configure your XML files:
Create a views.xml file under WEB-INF folder and paste the following code into it:
Add this config to you spring configuration file:
Make sure to set the order if you are using any other view resolvers.
Now you just have to use "jsonView" as the viewname and the model will be converted to JSONbefore being sent back to the client: