-1

I cannot parse json arabic test.I am sending request in json as {"SUBJECT_AR":"أهلا بك"}.But while reading this jsonobject in spring i am getting ?????.The content type for this jsonobject while sending the request is application/json;charset=utf-8.I have added produces="application/json;charset=utf-8" to the rest controller even though it is not working.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
sandybelieve
  • 45
  • 3
  • 7
  • What *exactly* do you mean by "i am getting `?????`"? Is that in the debugger, in logs, in your web page output? You say you're "sending request" - to what? It's very unclear whether the problem is in receiving the text, parsing the text, sending output... please provide a lot more context. – Jon Skeet Apr 21 '17 at 09:59
  • while parsing the jsonobject which is in request means while i try get as jsonobject.getString("SUBJECT_AR") to some string it is printing "?????". – sandybelieve Apr 21 '17 at 10:08
  • What do you mean by "it is printing"? In the debugger? In a page? Have you validated whether the request itself has been received correctly *before* being parsed as JSON? What's sending the request, and have you validated that it's *really* using UTF-8? There's still *so* much information missing here... – Jon Skeet Apr 21 '17 at 10:10
  • while sending request my json is {"SUBJECT_AR":"أهلا بك"} but when request comes to server i am getting json as {"SUBJECT_AR":"????"} – sandybelieve Apr 21 '17 at 10:18
  • But you've skipped a number of places that things can go wrong: what do the bytes look like in the request? Are they being parsed correctly to a JSON string before that JSON is being parsed itself? And you *still* haven't explained how you're seeing those "?????". There's a lot more diagnostic work to do, and you need to put significantly more effort into explaining your context. – Jon Skeet Apr 21 '17 at 10:23

1 Answers1

0

Add the following code in your web.xml (inside web-app tag) and retry:

<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Ehsan Khodarahmi
  • 4,772
  • 10
  • 60
  • 87