title: How to Return CSV Data in Browser From Spring Controller
body: <p>Let say I have CSV data in a string and want to return it from a Spring controller.  Imagine the data looks like this</p>
  
  <pre><code>a,b,c 
  1,2,3
  4,5,6
  </code></pre>
  
  <p>No matter what I have tried, the newlines come out as literally '\n' in the response content, and if I double escape them as in "\n", the response just contains the double backslashes too.  In general, how to I return plain text data with newlines in it without the newlines being modified?  I know how to return plain text, but still, the content comes with escaped newlines...  This is what I current have (using Spring 3.0.5, not by choice)</p>
  
  <pre><code>@RequestMapping(value = "/api/foo.csv")
  public ResponseEntity&lt;String&gt; fooAsCSV() {
  
      HttpHeaders responseHeaders = new HttpHeaders();
      responseHeaders.add("Content-Type", "text/plain; charset=utf-8");
  
      String data = "a,b,c\n1,2,3\n3,4,5";
      return new ResponseEntity&lt;&gt;(data, responseHeaders, HttpStatus.OK);
  }
  </code></pre>
  
  <p>Which produces literally the string </p>
  
  <pre><code>"a,b,c\n1,2,3\n,3,4,5"
  </code></pre>
  
  <p>In the browser.  How do I make it produce the correct data with new lines in tact as shown above?</p>