When I am passing application/json parameters from Chrome Rest Client,I am getting 400 bad request error. When I add required=false for @RequestParam, the request is accepted by Controller but the values is Null.
@RequestMapping(value = "/add",
method = RequestMethod.POST,
consumes="application/json",
produces="application/json")
public @ResponseBody String add(
@RequestParam(value="surveyName") String surveyName,
@RequestParam(value="surveyDesc") String surveyDesc,
ModelMap model) throws Exception
{
System.out.println("request parameters in /add/syrvey surveyName= "+surveyName);
}
My JSON request is as below and Content-Type is "aplication/json"
{"surveyName"="sd", "surveyDesc":"sd"}
I tried using headers="Accept=application/json",but it didn't help much.
My dispatcher-servlet is
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=">
<context:annotation-config />
<context:component-scan base-package="com.survey.controller" />
<context:component-scan base-package="com.survey.service" />
<context:component-scan base-package="com.survey.dao" />
<context:component-scan base-package="com.survey.entity" />
<context:component-scan base-package="com.survey.constants" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter" />
</list>
</property>
</bean>
</beans>
My pom.xml is
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
Any help greatly appreciated