title: Spring mvc : Changing default Response format from xml to json
body: <p>I have gone through other similar asked questions but nothing worked for me.</p>
  
  <p>All my <strong>API's return JSON</strong> as response <strong>by Default</strong>:</p>
  
  <p>Because of some XML API,  i had to add jackson-xml </p>
  
  <pre><code>    &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-dataformat-xml&lt;/artifactId&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>Now</strong> by default "<strong>Without accept header" All responses are XML</strong>.</p>
  
  <p>I would like to have <strong>JSON as default Response format</strong> .</p>
  
  <p>As stated in the doc here:</p>
  
  <p><a href="https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc" rel="noreferrer">https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc</a></p>
  
  <p>I implemented the following config :</p>
  
  <pre><code>@Override
      public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
          configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true)    
                  .useJaf(false).defaultContentType(MediaType.APPLICATION_JSON)
                  .mediaType("xml", MediaType.APPLICATION_XML).mediaType("json", MediaType.APPLICATION_JSON);
      }
  </code></pre>
  
  <p><strong>Case 1:</strong> if i make the <code>ignoreAcceptHeader(true)</code>    then everything is JSON even the XML API returning JSON.</p>
  
  <p><strong>Case 2:</strong> when <code>ignoreAcceptHeader(false)</code> is then default is XML.</p>
  
  <p>I forget to mention my API's look like this:</p>
  
  <pre><code>@RequestMapping(value = "/getXml", method = RequestMethod.GET)
  public ResponseEntity&lt;String&gt; getXml( HttpServletRequest request)
          throws JAXBException {
      return returnXml();
  }
  </code></pre>
  
  <p>I am quite lost here, All i want is Default(Without AcceptHeader) should be JSON.  (API returns XML as String) </p>
  
  <p>And when Accept Header : "Application/xml" is defined then response should be XML.</p>
  
  <p>Any advice would be of great help.</p>
  
  <p>Thanks.</p>