i am having issue showing ® symbol in browser. it is shown as � .
from my controller i am returning the json string.
i tried to use ResponseEntity<String> and setting up content-Type but that is also not working.
please let me know how i can resolve the issue.
I am confused. What do you mean tried to use ResponseEntity<String>
For setting the response body to be in json. You just annotate your return object with @ResponseBody. And have Apache Jackson jar in your classpath and <mvc:annotation-driven/> in your xml. That is all.
i was trying to set content type in response but i did not have any way to set that.
i googled that and some one suggested to use ResponseEntity<String> as return type and setting response headers in that.
but this was also not working.
now i have resolved this by putting HttpResponse in method arguments and instead of returning @ResponseBody writing the string on response.getWriter() and setting content type like HttpServletResponse.setcontenttype("argument").
can you suggest me how can i achieve same with @responsebody.
Well, you really aren't supposed to set it. It isn't the serverside's responsibility in RESTful Web Services. So therefore, unless you do it like you did, it happens automatically.
Basically, a major tenant of REST is that the client determines the format of the data that it wants. In the Request the client adds to the Request Header the format they want the data back. So if a request comes in asking for JSON, then Spring REST will automatically convert the Controller's returned object into JSON.
Joined: Feb 11, 2010
Thanks for the info Mark..
but actually the problem was i had some special character like Chinese and copyright symbol which were not getting displayed in UI.
that's why i need to set character encoding in the response.
for the Json response we are doing exactly like you said but we don't have any ways to set character encoding until unless i am passing HttpResponse as method argument and modify the character encoding there.