title: How to configure custom MediaType in Spring MVC?
body: <p>Using Spring MVC, I have controllers already working for both JSON and XML media formats.
  In the content negotiation configuration, I would like to rely on Accept header only, and introduce a custom name media type, for example: "myXml"</p>
  
  <p>My configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class WebConfig extends WebMvcConfigurerAdapter {
      @Override
      public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
          configurer
             .favorPathExtension(false)
             .favorParameter(false)
             .ignoreAcceptHeader(false)
             .useJaf(false)
             .mediaType(MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON)
             .mediaType(MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_XML)
             .mediaType("myXml", MediaType.APPLICATION_XML)
             .defaultContentType(MediaType.APPLICATION_JSON);
      }
  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>@RequestMapping(value = "/manager/{id}",
          method = RequestMethod.GET,
          produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}
  )
  @ResponseBody public Manager managers(@PathVariable long id){
      return repo.getManagerById(id);
  }
  </code></pre>
  
  <p>It works pretty well, Accept header: <code>application/json</code> produces JSON, <code>application/xml</code> produces XML. Anything else returns 406 Not Acceptable, even <code>myXml</code>. </p>
  
  <p>I expected xml though...</p>