title: spring mvc restcontroller return json string
body: <p>I have a Spring MVC controller with the following method:</p>
  
  <pre><code>@RequestMapping(value = "/stringtest", method = RequestMethod.GET)
  public String simpletest() throws Exception {
      return "test";
  }
  </code></pre>
  
  <p>This sits inside a controller that starts like this:</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/root")
  public class RootController
  </code></pre>
  
  <p>When I call other methods that return objects, those objects are serialized by Jackson into JSON.  But this method which returns a String is not converted to JSON.  In case it's not clear, here's an example using curl:</p>
  
  <pre><code>$curl http://localhost:8080/clapi/root/stringtest 
  test
  </code></pre>
  
  <p>So the problem is that "test" without any quotes is not a JSON string, but my REST client is expecting a string.  I expected the curl command to show that string with quotes around it so it's legal JSON instead:</p>
  
  <pre><code>"test"
  </code></pre>
  
  <p>I am using Spring WebMVC 4.1.3 and Jackson 2.4.3.  I have tried adding a "produces" attribute to the RequestMapping to say it should return JSON.  In this case, the Content-Type attribute sent back is "application/json" but still the test string is not quoted.</p>
  
  <p>I could workaround this by calling a JSON library to convert by Java String to JSON, but it seems like Spring MVC and Jackson generally do this automatically.  Yet somehow they are not doing it in my case.  Any ideas what I might have configured wrong to be getting just test back instead of "test"?</p>