Spring MVC Json Response Example

JSON objects or Strings can be returned from Spring MVC controllers using some simple steps. Lets see some Spring MVC Json response examples in this post.

What is JSON?

JSON is a way of easily exchanging and storing data. JSON is all about key/value pairs.You can read more about JSON on Wiki.

The important points to remember for getting the JSON response are
1. Marking the mvc as annotation driven.
2. Adding Jackson dependency to pom.xml
3. Creating a model class that we need to send as JSON
4. Using the @ResponseBody in the Controller return value.
5. Using the produces = "application/json" in the @RequestMapping

1. Dispatcher Servlet

2. Jackson configuration in pom.xml

3. Employee Model

4. The Controller

Output

spring mvc json response example using @ResponseBody

Download Full Code – SpringMVCJsonGet.zip

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn