Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 4.1.1 RELEASE and @ResponseBody return HTTP 406

I am using @ResponseBody to return Json object in Spring MVC. It works as expected on release 4.0.7 and 3.2.11, but it returns HTTP status 406 when I try to use the latest Spring release 4.1.1(as of 10/16) with no any other configuration changes. Is this considered a bug or the 4.1.1 requires different configuration?

the latest jackson jar is already in the classpath

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>

The example on the Spring document works fine

@RequestMapping(value = "/something", method = RequestMethod.PUT)
@ResponseBody
public String helloWorld() {
  return "Hello World";
}

when the return type is String. The problem happens when the return type is a POJO.

like image 416
Dino Tw Avatar asked Oct 17 '14 00:10

Dino Tw


1 Answers

Maven pom.xml:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.4.3</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.3</version>
    </dependency>

and spring mvc config file (eg:spring-mvc.xml)

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
    </mvc:message-converters>
</mvc:annotation-driven>
like image 51
Vito Avatar answered Sep 28 '22 04:09

Vito