title: JSON Incorrectly Returns Using Spring MVC 3.2 Deferred Result
body: <p>I am attempting to use Spring MVC 3.2 asynchronous deferred results for a RESTful JSON service.</p>
  
  <p>Using the synchronous approach:</p>
  
  <pre><code>@ResponseBody
  @RequestMapping(value = "/catalog", method = RequestMethod.GET, produces = "application/json")
  public Entry catalog() {
    Entry entry = new Entry();
    entry.timestamp = System.currentTimeMillis();
    entry.summary = "Hello World!";
    entry.body = new HashMap&lt;String, Object&gt;();
    entry.body.put("key1", "value1");
    entry.body.put("key2", "value2");
    entry.body.put("key3", "value3");
    return entry;
  }
  </code></pre>
  
  <p>I get the following JSON result:</p>
  
  <pre><code>{"timestamp":1359721240340,"summary":"Hello World!","body":{"key3":"value3","key2":"value2","key1":"value1"}}
  </code></pre>
  
  <p>Using the asynchronous approach (contrived example):</p>
  
  <pre><code>@ResponseBody
  @RequestMapping(value = "/catalogs", method = RequestMethod.GET, produces = "application/json")
  public DeferredResult&lt;Entry&gt; catalogs() {
      Entry entry = new Entry();
      entry.timestamp = System.currentTimeMillis();
      entry.summary = "Hello World!";
      entry.body = new HashMap&lt;String, Object&gt;();
      entry.body.put("key1", "value1");
      entry.body.put("key2", "value2");
      entry.body.put("key3", "value3");
      DeferredResult&lt;Entry&gt; result = new DeferredResult&lt;Entry&gt;();
      result.setResult(entry);
      return result;
  }
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>{}{"timestamp":1359721240340,"summary":"Hello World!","body":{"key3":"value3","key2":"value2","key1":"value1"}}
  </code></pre>
  
  <p>So what's the deal with the prefixed empty object (i.e. {})? Am I doing something obviously stupid or does <code>MappingJackson2JsonView</code> not play nice with the new Async features?</p>
  
  <p>F.Y.I here is my Spring MVC bean configuration:</p>
  
  <pre><code>&lt;bean
      class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
      &lt;property name="order" value="1" /&gt;
      &lt;property name="contentNegotiationManager"&gt;
          &lt;bean class="org.springframework.web.accept.ContentNegotiationManager" /&gt;
      &lt;/property&gt;
      &lt;property name="defaultViews"&gt;
          &lt;list&gt;
              &lt;bean
                  class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="order" value="2" /&gt;
      &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  </code></pre>