title: Spring MVC @ResponseBody returning a Map produces "Error 406 NOT ACCEPTABLE"
body: <p>I'm having a problem trying to set up @ResponseBody to return a collection. I have JAXB jars in the classpath and I didn't set up any ContentNegotiatingViewResolver.</p>
  
  <p>This is my simple object:-</p>
  
  <pre class="lang-java prettyprint-override"><code>@XmlRootElement(name = "test-object")
  @XmlAccessorType(XmlAccessType.FIELD)
  public class TestObject implements Serializable {
  
      @XmlAttribute
      private int id;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>I wrote a simple test that returns a single object... this works without problem, and I'm able to see the generated XML:-</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = "one", method = RequestMethod.GET)
  public @ResponseBody TestObject getSingleObject() {
      TestObject obj = new TestObject();
      obj.setId(1);
  
      return obj;
  }
  </code></pre>
  
  <p>What I really want is to return a list of objects. After reading around, it seems like the way to do so is to place the list in a map and return the map:-</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = "all", method = RequestMethod.GET)
  public @ResponseBody Map&lt;String, ? extends Object&gt; getAllObjects() {
      TestObject obj1 = new TestObject();
      obj1.setId(1);
  
      TestObject obj2 = new TestObject();
      obj2.setId(2);
  
      List&lt;TestObject&gt; list = Arrays.asList(obj1, obj2);
  
      return Collections.singletonMap("all-objects", list);
  }
  </code></pre>
  
  <p>When I execute the above, I'm getting "Error 406 Not Acceptable".</p>
  
  <p>What did I do wrong here? I'm running on Jetty 6.1 if that makes a difference.</p>
  
  <p>Thanks.</p>