chaity
chaity

Reputation: 155

Language specific characters in json

I need to send some language specific characters in my json to a local tomcat server I am running. Everytime it encounters those characters, it says "400 - Request is syntactically incorrect", as expected

Any work arounds? Also, I don't want it to support certain specific languages, but keep it generic and support all languages that the browser sending the request supports.

Supporting Spring MVC at the backend, which will process the json input

Sample:

абвгдеёжзийклмнопрстуфхцчшщъыьэюя=один

Controller code:

    @RequestMapping(value = "/services", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)

public ResponseEntity<Response1> executeService(
                @RequestBody Request1 request) {
    //controller code
    }

Json request:

{
  "serviceName":"abc",
  "input":{
    "text":"абвгдеёжзийклмнопрстуфхцчшщъыьэюя=один"
  }
}

P.S. Json is valid for English characters, controller works normally if I send normal English characters, and correct output is displayed in that case.

Check comments for specific errors faced

Upvotes: 0

Views: 1052

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328614

This isn't valid JSON. Valid JSON would look like this:

{"абвгдеёжзийклмнопрстуфхцчшщъыьэюя" : "один"}

The other usual culprit is the charset or encoding. JavaScript uses Unicode for strings and any JSON framework worth its salt will use UTF-8 encoding when preparing the data for the wire. So unless you're trying to do everything yourself (not using any framework) or you're tampering with the headers and especially the Content-Type header, this should work out of the box.

If these two suggestions don't solve your problem, you'll have to show us your code.

Upvotes: 2

Related Questions