Whenever a user enters a mobile emoji like 😀 into the input field on my website, it is saved as ?? in the database.
The emojis are encoded in utf8mb4, so I have already updated the database collation to utf8mb4_general_ci.
Although the emoticons can be successfully saved now, when transferring a message containing an emoji from a client to my server, it still gets changed into ?? somewhere along the way. I am currently trying to pinpoint where and how to solve this issue.
The message is sent to the server through the following ajax call:
function updateStatus() {
var status = $("#status").val();
jsRoutes.controllers.Userdata.updateStatus( status ).ajax({
success : function(data) {
$("#profil").cftoaster({content: data});
},
error : function(err) {
$("#profil").cftoaster({content: err.responseText});
}
});
}
On the server side, I am using the java-based Play Framework 2.4.4. Here is the beginning of the method called in the ajax request:
public static Result updateStatus(String status) {
String receivedName = Application.getSessionUser();
Logger.debug("RecvStatus: " + status);
...
}
The Logger output already shows ??
for an emoticon.
The route configuration looks like this:
PUT /status/ controllers.Userdata.updateStatus(status: String)
EDIT:
To ensure that the transfer from client to server is correct, I am now sending the actual Unicode values. I have modified my server-side function as follows:
Logger.debug("RecvStatus: " + status);
status = status.replace("\\","");
String[] arr = status.split("u");
status = "";
for(int i = 1; i < arr.length; i++){
int hexVal = Integer.parseInt(arr[i], 16);
status += (char)hexVal;
}
Logger.debug("RecvStatus: " + status);
This results in the following output:
[debug] application - RecvStatus: \ud83d\ude01
[debug] application - RecvStatus: ?
which indicates that the issue probably lies within Java.