title: How to return a string as valid JSON from Spring web app?
body: <p>I have a Spring endpoint for my REST web services app that I want to return a string:</p>
  
  <pre><code>"Unauthorized: token is invalid"
  </code></pre>
  
  <p>But my javascript on the front-end chokes on this:</p>
  
  <pre><code>JSON.parse("Unauthorized: token is invalid") //Unexpected token U
  </code></pre>
  
  <p>How do I get my app to return a valid JSON string? Here is my current code:</p>
  
  <pre><code>@RequestMapping(value="/401")
  public ResponseEntity&lt;String&gt; unauthorized() {
      return new ResponseEntity&lt;String&gt;("Unauthorized: token is invalid", HttpStatus.UNAUTHORIZED);
  }
  </code></pre>