Search code examples
javaspring-bootmicroservicesresttemplatespring-rest

How to Send Emojis using RestTemplate in Spring Boot?


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 😗"
}

displays in service B as

{
"from": "1233222225",
"to":  "8585855858",
"message": "Hello A, hope you are doing 23012020 ?"
}

Can anyone help to solve this problem?


Solution

  • Try with this solution. it is working for me

    while sending json data make sure that content type should be "application/json;charset=UTF-8" in headers. default it will take "application/json".

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType("application/json;charset=UTF-8");