title: Spring 406 error while trying to return object in @ResponseBody
body: <p>my web.xml:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;rest-dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;rest-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>pom.xml:</p>
  
  <pre><code>...
  &lt;jackson.mapper.version&gt;1.9.13&lt;/jackson.mapper.version&gt;
  ...
      &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core-lgpl&lt;/artifactId&gt;
          &lt;version&gt;${jackson.mapper.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core-asl&lt;/artifactId&gt;
          &lt;version&gt;${jackson.mapper.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-mapper-lgpl&lt;/artifactId&gt;
          &lt;version&gt;${jackson.mapper.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
          &lt;version&gt;${jackson.mapper.version}&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>rest-services-config.xml:</p>
  
  <pre><code>&lt;mvc:annotation-driven /&gt;
  &lt;context:component-scan base-package="com.example.web.rest" /&gt;
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"&gt;
      &lt;property name="contentType" value="text/plain"/&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;util:list id="beanList"&gt;
              &lt;ref bean="jsonMessageConverter"/&gt;
          &lt;/util:list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/&gt;
  </code></pre>
  
  <p>rest-dispatcher-servlet.xml:</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.example.web.rest" /&gt;
  
  
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;WEB-INF/pages/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.html&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;mvc:resources mapping="/WEB-INF/pages/**" location="/WEB-INF/pages/" /&gt;
  &lt;mvc:resources mapping="/vendors/**" location="/resources/vendors/" /&gt;
  &lt;mvc:resources mapping="/controls/**" location="/resources/controls/" /&gt;
  &lt;mvc:resources mapping="/css/**" location="/resources/css" /&gt;
  &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  &lt;mvc:annotation-driven /&gt;
  </code></pre>
  
  <p>Finally, here is my controller:</p>
  
  <pre><code>@Controller
  @RequestMapping("/user")
  public class UserService {
  
  @Autowired(required=true)
  private UserDaoImpl dao;
  
  @RequestMapping(value="/getCurrentUserCredentials/", method = RequestMethod.GET)
  public @ResponseBody UserCredentials getCurrentUserCredentials() {
      HttpSession session = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getSession();
      try {
          return dao.getCurrentUserCredentials((Integer)session.getAttribute("userid"));
      } catch (Exception e) {
          return null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>...and request which gives to me a 406error:</p>
  
  <pre><code>    $.ajax({
              type: 'GET',
              url: 'user/getCurrentUserCredentials/',
              dataType: 'json',
              success: function(data) {console.log(data); self.currentUserCredentials(data);},
              error: function() {console.log('error');}
          });
  </code></pre>
  
  <hr>
  
  <p>Any suggestions about solving this? Help please. </p>
  
  <p>Controller's method returns correct data (checked in debug) while this data can't be handled properly.</p>