I'm using Spring 3.1 and I have a handler that should return a String value. Here's how my handler looks like:
@RequestMapping(value = TEST_HANDLER_PATH, method = RequestMethod.POST)
public ResponseEntity<String> handleTest(HttpServletRequest request,
@RequestParam("parma1") String param) throws Exception {
String ret = ...
...
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "text/plain;charset=utf-8");
return new ResponseEntity<String>(ret, headers, HttpStatus.CREATED);
}
I also tried annotating method with @ResponseBody
with return ret;
at the end.
In both cases, when I hit the service, I get extra quotes around String value (e.g. "This is a test"
).
I'm guessing this is due to message conversion. That's why I tried defining Content-Type
header, to hit StringHttpMessageConverter explicitly, to no avail.