How to Send Emojis using RestTemplate in Spring Boot?

Ran*_*ala 0 java resttemplate spring-boot microservices spring-rest

My requirement is to send JSON data from service (A) to another service (B), in this case, I am sending emojis in JSON using Spring Boot RestTemplate. If I send a request from A to B, in the service B the message is displayed as a text with a question mark(?) instead of emoji.

Sending this JSON data

{
"from": "1233222225",
"to":  "8585855858",
"message": "Hello A, hope you are doing 23012020 "
}
Run Code Online (Sandbox Code Playgroud)

displays in service B as

{
"from": "1233222225",
"to":  "8585855858",
"message": "Hello A, hope you are doing 23012020 ?"
}
Run Code Online (Sandbox Code Playgroud)

Can anyone help to solve this problem?

小智 6

尝试使用此解决方案。它对我有用

发送 json 数据时,请确保标头中的内容类型应为“application/json;charset=UTF-8”。默认情况下它将采用“application/json”。

HttpHeaders headers = new HttpHeaders();
headers.setContentType("application/json;charset=UTF-8");
Run Code Online (Sandbox Code Playgroud)