title: Same mapping for endpoint accepting object and collection of same object
body: <p>In my Spring based REST API I want to use the same endpoint when creating <strong>one</strong> new resource as for creating <strong>multiple</strong> new resources.</p>
  
  <p>In other words, I want to be able to post both </p>
  
  <pre><code>{
    name: John
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>[
    {
      name: John
    },
    {
      name: Peter
    }
  ]
  </code></pre>
  
  <p>to the same endpoint <code>/api/persons</code>.</p>
  
  <p>In my Spring controller I therefore want to map two methods to the same path, but accepting different arguments:</p>
  
  <pre><code>@RequestMapping("/clases")
  public class PersonController {
    @Autowire
    private PersonService personService;
  
    @RequestMapping(method = RequestMethod.POST)
    public Person createPerson(@RequestBody Person person) {
      return personService.create(person);
    }
  
    @RequestMapping(method = RequestMethod.POST)
    public Set&lt;Person&gt; createPersons(@RequestBody Set&lt;Person&gt; persons) {
      return personService.create(persons);
    }
  }
  </code></pre>
  
  <p>This causes Spring to throw an exception during startup due to an ambiguous mapping of the endpoint. One would hope Spring could distinguish between these methods at runtime depending on what is posted to the endpoint, but that doesn't seem to be the case.</p>
  
  <p>Since this is a very common pattern in RESTful design, I'm hoping there is a thought out solution to this that I've missed. Is there? Or is there any workaround?</p>
  
  <p><em>PS. There are other similar questions on the forum regarding this problem, but none of them mentions my case where one method accepts a type and the other method accepts a collection of the <strong>same</strong> type.</em></p>