#1 2019-11-11 20:25:28

JD
Member
Registered: 2015-08-20
Posts: 101

Problems handling spaces (Java strings to FreePascal strings)

Hi there everyone,

I have a mORMot REST server and I'm trying to send requests to it from a Java application.

Java strings are UTF16 by default and I want to get a list of users from the backend database by
sending query parameters in JSON format to the REST server.

I send a JSON string like this to the mORMot server:

{"etat":"Comptes activés"}

The mORMot server truncates the JSON string as follows:

{"etat":"Comptes

I made some changes and I noticed that the JSON string is not truncated when I send the
string with an underscore between the two words as follows:

{"etat":"Comptes_activés"}

The mORMot REST method looks like this

function TRESTMethods.Utilisateurs(Params: RawUTF8): RawJSON;
var
  Res: ISQLDBRows;
  Ctxt: TServiceRunningContext;
  vParams: Variant;
begin
  // Get the parameters - Java strings are UTF-16 by default so a convertion to
  // UTF-8 is necessary here
  vParams := _JsonFast(StringToUTF8(Params));

  // NOTE vParams is empty when I send {"etat":"Comptes activés"} but it is OK
  // when I send {"etat":"Comptes_activés"} with an underscore between 'Comptes'
  // and 'activés'

  // Set the current service context
  Ctxt := CurrentServiceContext;

  //
  try
    // more code here
  finally
    Res := nil;
  end;
end;

Can anybody please help me resolve this problem.

Thanks a lot,

JD

Last edited by JD (2019-11-11 20:26:13)

Offline

#2 2019-11-11 21:07:00

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 336

Re: Problems handling spaces (Java strings to FreePascal strings)

You must encode url parameter (space = %20).


Esteban

Offline

#3 2019-11-11 23:20:26

JD
Member
Registered: 2015-08-20
Posts: 101

Re: Problems handling spaces (Java strings to FreePascal strings)

Thanks a lot for the tip Esteban. It works properly now.

JD

Offline

Board footer

Powered by FluxBB