Announcement Announcement Module
Collapse
No announcement yet.
json&unicode problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • json&unicode problem

    Hi,

    I have a problem with unicode for json.

    I've created test project:
    project --topLevelPackage com.test.roo --projectName jsonunicode --java 6
    persistence setup --provider HIBERNATE --database MYSQL --databaseName test --userName root
    entity --class ~.domain.MyCheck
    field string --fieldName name --sizeMax 50 --notNull
    json all
    controller all --package ~.web
    controller:

    @RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
    @ResponseBody
    public Object MyCheckController.showJson(@PathVariable("id") Long id) {
    MyCheck mycheck = MyCheck.findMyCheck(id);
    if (mycheck == null) {
    return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }
    return mycheck.toJson(); // here right Unicode text yet
    }
    and jsp works fine,

    but for json requests I got non-unicode text:
    {"id":1,"name":"????","version":null}
    with
    Response Headers
    Server Apache-Coyote/1.1
    Content-Type text/html;charset=UTF-8
    Content-Length 37
    Date Wed, 26 Jan 2011 14:59:05 GMT

    any suggestions please
    --
    Regards,
    Andriy
    Last edited by piskovyy; Jan 27th, 2011, 12:19 AM.

  • #2
    Fixed by
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "text/html; charset=utf-8");
    return new ResponseEntity<String>(check.toJson(), responseHeaders, HttpStatus.OK);

    --
    Regards,
    Andriy

    Comment


    • #3
      The bug there:
      public class StringHttpMessageConverter extends AbstractHttpMessageConverter<String> {
      public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
      Why is there "ISO-8859-1" ? And how can I change it to "UTF-8" by the easiest way?

      --
      Regards,
      Andriy

      Comment

      Working...
      X