0

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

chaity
  • 163
  • 2
  • 11

1 Answers1

2

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • I am sorry for not being clear, the string would be something like { "name" : "абвгдеёжзийклмнопрстуфхцчшщъыьэюя=один" } – chaity Apr 17 '15 at 07:50
  • That's valid JSON. Did you check whether the request looks correct on the wire? Most browsers today allow you to look at the data being sent and received. – Aaron Digulla Apr 17 '15 at 07:57
  • With charset=utf-8 header, 415 error is displayed Without that, request is syntactically incorrect and doesn't look fine on the wire either – chaity Apr 17 '15 at 08:00
  • See http://stackoverflow.com/questions/12990717/spring-mvc-the-request-sent-by-the-client-was-syntactically-incorrect and http://stackoverflow.com/questions/20616319/the-request-sent-by-the-client-was-syntactically-incorrect-spring-mvc-jdbc-te – Aaron Digulla Apr 17 '15 at 08:28