I am trying to hit request from postman consisting of arabic characters:
{ "data": "{\"holder passport expiry date\":\"10/09/2021\",\"holder passport issue date\":\"11/09/2011\",\"holder sponsor name\":\"رائد ابو زيدsss\",\"holder occupation code\":8}" }
While I am trying to print the request in console using logger.info or System.out.println like this:
public void printRecord(RequestBodyy requestBody) throws UnsupportedEncodingException, JSONException {
JSONObject jsonObject = new JSONObject(requestBody.getData());
System.out.println(jsonObject);
System.out.print(jsonObject.get("holder passport expiry date"));
String str2 = new String("رائد ابو زيدsss");//.getBytes(), "UTF-8");
System.out.println(str2);
String str = new String(jsonObject.get("holder sponsor name").toString());//.getBytes(),"UTF-8");
System.out.println(str);
String data = "{\"eidaID\":\"حسن\"}"; JSONObject obj = new JSONObject(data);
System.out.println(obj.get("eidaID").toString());
}
Output:
{"holder sponsor name":"???? ??? ???sss","holder passport expiry date":"10/09/2021","holder occupation code":8,"holder passport issue date":"11/09/2011"}
10/09/2021???? ??? ???sss
???? ??? ???sss
???
I am receiving ???? instead of those arabic characters.
How will I able to do that ?
However, I am able to store these characters in DB coming from API request.
My application.properties :
server.port = 8076
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.jpa.properties.hibernate.connection.characterEncoding=utf-8
spring.jpa.properties.hibernate.connection.CharSet=utf-8
spring.jpa.properties.hibernate.connection.useUnicode=true
server.tomcat.uri-encoding=UTF-8
In pom.xml, I added:
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Please help!