I have a rest web service that accepts a POST/PUT, the resource sent in the body of the rest call contains both French and Arabic characters , but when I send a resource that contain some Arabic characters, I get question marks stored in the database instead, as following : ?????
.
When I type the Arabic characters manually in the database it's stored without any problem, this only happened when I use POST or PUT, in the other hand, The GET method works and it gets the Arabic characters.
This is the Request Headers source :
PUT /candidature/candidats HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 480
Accept: application/json, text/plain, */*
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://localhost:8080/app/index.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
As you can see in the Content-Type I have charset=UTF-8
, so it should work in this case.
This is an example of a resource I'm sending in the PUT/POST method :
{"username":"ichigo","nom":"Kurusaki","prenom":"Ichigo","nomarab":"كوروساكي","prenomarab":"إيتشيغو","genre":"M"}
In this case after a POST/PUT the GET method will get the Arabic characters as question marks:
{"codeUser":null,"username":"Asus","nom":"sdf","prenom":"Mbarek","nomarab":"????????","prenomarab":"???????","genre":"M"}
But when I type them manually to the database and then I call the GET method, this is the result I'm getting :
{"codeUser":null,"username":"ichigo","nom":"Kurusaki","prenom":"Ichigo","nomarab":"كوروساكي","prenomarab":"إيتشيغو","genre":"M"}
So this problem happens only with the POST/PUT methods.
I'm using AngularJS in the client side and Spring boot in the server side.
So why I'm getting this behavior ? and how can I solve it ?
Edit :
In the server side I printed the Arabic values before I save them using Spring boot data as following :
System.out.print("arabicName : " + candidat.getNomarab());
and in console I got this :
arabicName : كوروساكي
So this happens when I call the saveAndFlush
method of the Sring Boot Data JPA.