In this tutorial, we show you how to output JSON data in Spring MVC framework.
Oct 05, 2016 Hi I am new to Spring Security and Spring Oauth, i am configuring a Spring Oauth Server and Resource Server java based. But i need to configure some of the web mvc based on xml, like need to initialize servlet parameters. Informational - These status codes indicate a provisional response. The client should be prepared to receive one or more 1xx responses before receiving a regular response. Switching protocols. Success - This class of status codes indicates that the server successfully accepted the client request.
Technologies used :
- Spring 3.2.2.RELEASE
- Jackson 1.9.10
- JDK 1.6
- Eclipse 3.6
- Maven 3
P.S In Spring 3, to output JSON data, just puts Jackson library in the project classpath.
1. Project Dependencies
Get Jackson and Spring dependencies.
2. Model
A simple POJO, later output this object as formatted JSON data.
3. Controller
Add
@ResponseBody
as return value. Wen Spring sees- Jackson library is existed in the project classpath
- The
mvc:annotation-driven
is enabled - Return method annotated with @ResponseBody
Spring will handle the JSON conversion automatically.
JSONController.java
4. mvc:annotation-driven
Enable
mvc:annotation-driven
in your Spring configuration XML file.5. Demo
URL : http://localhost:8080/SpringMVC/rest/kfc/brands/kfc-kampar