I am using Spring MVC with JSON as specified in Ajax Simplification Spring 3.0 article.
After so many attempts and variations of my code depending on advice found on
Instead of @RequestMapping(...headers="Accept=application/json"...)
use @RequestMapping(... , produces = "application/json")
I also faced this same issue and I downloaded this [jar]: (http://www.java2s.com/Code/Jar/j/Downloadjacksonall190jar.htm)! and placed in lib folder and the app works like a charm :)
As said by axtavt, mvc:annotation-driven and jackson JSON mapper are all that you need. I followed that and got my application to return both JSON and XML strings from the same method without changing any code, provided that there are @XmlRootElement and @XmlElement in the object you are returning from the controller. The difference was in the accept parameter passed in the request or header. To return xml, any normal invocation from the browser will do it, otherwise pass the accept as 'application/xml'. If you want JSON returned, use 'application/json' in the accept parameter in request.
If you use firefox, you can use tamperdata and change this parameter
Add org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
and org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
to DispatcherServlet-servlet.xml. and refer to the the first one in the second using
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter"/>
</list>
</property>
</bean>
issue is not related to jquery . even bug is saying it is server side issue . please make sure that following 2 jar present in class path :-
jackson-core-asl-1.9.X.jar jackson-mapper-asl-1.9.X.jar
To return JSON response from @ResponseBody
-annotated method, you need two things:
<mvc:annotation-driven />
(you already have it)You don't need ContentNegotiatingViewResolver
and headers
in @RequestMapping
.