spring mvc not returning json content - error 406
Solution 1:
To return JSON response from @ResponseBody
-annotated method, you need two things:
-
<mvc:annotation-driven />
(you already have it) - Jackson JSON Mapper in the classpath
You don't need ContentNegotiatingViewResolver
and headers
in @RequestMapping
.
Solution 2:
I had this problem after I upgraded Spring to 4.1.x from 3.2.x. I fixed by upgrading Jackson from 1.9.x to 2.2.x (fasterxml)
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.3</version>
</dependency>
Solution 3:
Try remove the header limitation for Accept
, put a breakpoint and see what's the actual value. Or do this with FireBug.
Also take a look at this jquery issue