title: SpringMVC JSON unsupported type
body: <p>I have a Spring MVC 3.2 app that isn't accepting a JSON POST request from a browser.  If I use a tool such as CocoaRest, all is fine.  But when I use a browser or tool like chrome://restclient/content/restclient.html then I get </p>
  
  <blockquote>
    <p>HTTP Status 415 -The server refused this request because the request
    entity is in a format not supported by the requested resource for the
    requested method.</p>
  </blockquote>
  
  <p>Here is my configuration: </p>
  
  <pre><code>@Bean
  public ContentNegotiationManagerFactoryBean contentNegotiationManager() {
      Properties properties = new Properties();
      properties.setProperty( "xml", "application/xml" );
      properties.setProperty( "json", "application/json" );
      properties.setProperty( "html", "application/html" );
  
      ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
      contentNegotiationManager.setFavorParameter( true );
      contentNegotiationManager.setMediaTypes( properties );
      contentNegotiationManager.setIgnoreAcceptHeader( true );
  
      contentNegotiationManager.setDefaultContentType( MediaType.APPLICATION_JSON );
  
      return contentNegotiationManager;
  }
  </code></pre>
  
  <p>and my pom:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
      &lt;version&gt;2.0.4&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
      &lt;version&gt;2.0.4&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;1.9.13&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>@Transactional
  @ResponseBody
  @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)public EmployeeDTO addEmployee(@PathVariable String officeName, @RequestBody @Valid final Employee employee,
                                     BindingResult result) {
          List&lt;String&gt; errors = new ArrayList&lt;String&gt;();
          if ( result.hasErrors() ) {
              for ( ObjectError error : result.getAllErrors() ) {
                  errors.add( error.getDefaultMessage() );
              }
              throw new EmployeeSetupException( errors, "Employee could not be configured, please check your submitted values." );
          }
  ...
  }
  </code></pre>
  
  <p>Here is my request:</p>
  
  <pre><code>{
    "address" : {
      "status" : null,
      "city" : "Lakewood",
      "addressId" : 1,
      "seqId" : null,
      "addressLine1" : "123 Maple Ave",
      "zip" : "80111",
      "addressLine2" : "Apt 101",
      "zipLong" : null,
      "addressLine3" : "room C ",
      "state" : "CO"
  
    },
    "office" : null,
    "licenseNumber" : "0987654321A",
    "scheduleId" : null,
    "user" : {
      "status" : 1,
      "userName" : "sid3@spistols.com",
      "userRole" : {
        "userRoleDescription" : "The person or entity that owns a particular practice, who has the highest level of authorization",
        "userRoleDescriptionShort" : "Practice Owner",
        "userRoleId" : 20
      }
    },
    "firstName" : "Sid",
    "ssn" : "111-22-3332",
    "specialtyId" : null,
    "lastName" : "Vicious",
    "fullName" : null
    }
  </code></pre>
  
  <p>I read some articles that say setting the header content to application/json or form will do it.  But when I set the contentType to application/json and/or application/x-www-form-urlencoded it still fails within the browser.  I have also tried submitting via jQuery but I get the same result.</p>
  
  <p>if I change the controller from:</p>
  
  <pre><code> @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  </code></pre>
  
  <p>then I get this when I submit thru a browser:</p>
  
  <pre><code>Received Exception Content type 'text/plain;charset=UTF-8' not supported
  org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported
  at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:149)
      at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:180)
      at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:95)
      at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
      at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
  </code></pre>
  
  <p>That doesn't make sense since the Chrome rest client chrome://restclient/content/restclient.html shows a contentType of application/json for the request.</p>
  
  <p>If anyone knows what might be going wrong, I would certainly appreciate the help.</p>