title: How to set priority to Spring-Boot request mapping methods
body: <p>I have a Spring-Boot (v2.0.2) application with a RestController with 2 methods which only differ by the Accept header. A simplified version of the code is this:</p>
  
  <pre><code>@RestController
  @RequestMapping("/myapp")
  public class FooController {
  
      @GetMapping(value = "/foo/{id}", headers = "Accept=application/json", produces = "application/json;charset=UTF-8")
      public ResponseEntity&lt;String&gt; fooJson(@PathVariable id) {
          return foo(pageId, true);
      }
  
      @GetMapping(value = "/foo/{id}", headers = "Accept=application/ld+json", produces = "application/ld+json;charset=UTF-8")
      public ResponseEntity&lt;String&gt; fooJsonLd(@PathVariable id) {
          return foo(pageId, false);
      }
  
      private ResponseEntity&lt;String&gt; foo(String id, boolean isJson) {
          String result = generateBasicResponse(id);
          if (isJson) {
              return result
          }
          return addJsonLdContext(result);
      }
  </code></pre>
  
  <p>This works fine. If we sent a request with accept header such as <code>application/json;q=0.5,application/ld+json;q=0.6</code> for example it will return a json-ld response as it should. </p>
  
  <p>My problem is that if we sent a request with no accept header, an empty accept header or a wildcard <code>*/*</code> then it will by default always return a json response whereas I want the default response to be json-ld. </p>
  
  <p>I've tried various things to make the json-ld request mapping take priority over the json one:</p>
  
  <ul>
  <li>Reversing the order in which the mappings are declared.</li>
  <li>Adding an @Order annotation to both methods (with value 1 for json-ld and value 2 for the json method)</li>
  <li>Creating different classes and putting the @Order annotation at class-level</li>
  <li>Adding <code>Accept=*/*</code> as a second accept header to the json-ld mapping does work in giving it preference but has the unwanted side-affect that all accept headers are accepted, even unsupported types as <code>application/xml</code> for example.</li>
  </ul>
  
  <p>The only solution I can think of is creating one request-mapping method that accepts both headers and then processing the accept header ourselves, but I don't really like that solution. Is there a better, easier way to give preference to json-ld?</p>