#1 2023-04-30 10:15:18

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

records in Torm are escaped by GetJsonValues

Mormot.orm.base line 8830
procedure TOrmTableAbstract.GetJsonValues(
  W: TResultsWriter; RowFirst, RowLast: PtrInt; IDBinarySize: integer);

why a record in a TOrm is escaped?

Check the following definition:

  DOutMsgdata=packed record msg:Rawutf8; typ:ptrint; end;

  TOrmOutMsgbox=class(Torm)
    private
      Fdedo: DOutMsgdata;
      Fdat: Tdatetime;
    published
      property dat: Tdatetime read Fdat write Fdat;
      property dedo: DOutMsgdata read Fdedo write Fdedo;
  end;

I am getting the following:

[
    {
        "dat": "2023-04-30T12:15:17",
        "dedo": "{\"msg\":\"hello there\",\"typ\":0}"
    }
]

Is that ok?

Offline

#2 2023-04-30 16:29:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: records in Torm are escaped by GetJsonValues

The fact that they are written as a JSON string is pretty standard for the ORM - because they are expected to be stored as text in the database.
This GetJsonValues() method is aimed for DB storage, not general JSON serialization.

To be fair, published records are not yet supported, because they are available on latest Delphi versions, and not available on FPC.
So you are even lucky to get something. wink
smile

Offline

#3 2023-04-30 16:34:57

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: records in Torm are escaped by GetJsonValues

Record is registered with TRttiJson.RegisterFromText
I tried to have the property dedo as RawJSON but again it gets escaped

Do you recommend an other way to have it without been escaped?

Offline

#4 2023-04-30 16:36:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: records in Torm are escaped by GetJsonValues

It is escaped because this method is aimed to save as JSON for the database.

Try to use the regular ObjectToJSon() or SaveJson() functions.
But as I wrote, published record properties from classes is currently not supported nor tested - it is somewhat implemented.
Any feedback is welcome.

Offline

#5 2023-04-30 16:42:16

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: records in Torm are escaped by GetJsonValues

I am using a tormtable result from MultiFieldValues
Can I have a little help more?

Thank you in advance

Offline

#6 2023-04-30 17:49:34

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: records in Torm are escaped by GetJsonValues

As I can see it is returned from Tormtable escaped
I did the following:
var t:ormtable;
v:variant;
n:integer;
t.ToDocVariant(v,false);
for n:=0 to v._count-1 do 
v.value[n].dedo:=_jsonfast(v.value[n].dedo);

With the above the v has the correct view
Is there a better or safer way?

Last edited by dcoun (2023-04-30 18:08:50)

Offline

Board footer

Powered by FluxBB