Special characters (german umlaut) in CRUD endpoints

Hi,

I have implemented an apache module which is providing Rest API endpoints for Login and CRUD Data Table endpoints via XDATA and Aurelius functionality (I used TMS Data Modeler to create the unit). Apache is running on Ubuntu Linux.
I have also activated the swaggerui option and all is working fine. However when I submit a dataset via post or patch to the crud endpoint the special characters are converted into gibberish (Tester öäü -> Tester öäü).
I have created a middleware which logs the request's content to a logfile with this function:
procedure TAPMiddleware.ProcessRequest(Context: THttpServerContext; Next: THttpServerProc);
var
Stream: TArray<System.Byte>;
LogValue: String;
begin
if (Context.Request.ContentLength > 0) and Context.Request.Headers.Exists('authorization') then
begin
Stream := Context.Request.Content;
LogValue := TEncoding.UTF8.GetString(Stream, 0, Context.Request.ContentLength);
TMSDefaultLogger.Info(LogValue);
end;
Next(Context);
end;

The logged info in the logfile confirms that the data is actually UTF8:
[1/20/22 10:52:38 AM][Info][Value: {
"id": 14,
"auftragId": 1,
"lokation": "Tester öäü",
"zeitpunkt": "2020-12-20T10:10",
"sondersignal": "J",
"wartezeit": 0,
"bemerkungen": ""
}][Type: string]

The check is actually performed from the swaggerui
What am I missing here? I'm currently pulling my hair out over this.

Forgot to add, that the database is mysql 8.0.27 community and the tables use the charset utf8mb4. Firedac is used to connect to the database and Params.CharacterSet is set to csUtf8.
When I modify the data in the DB then the special characters are displayed properly by swaggerui, when performing a GET for the dataset.

I had a similar problem. Setting this global variable in the begining of the application solved it.
TGlobalConfigs.GetInstance.MapStringToNationalChar := True;

2 Likes

Thanks so much, this did the trick.

I have added Aurelius.Global.Config to my unit which creates the Server and then added the line to the initialization code of the unit right at the beginning.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.