You are not logged in.
Pages: 1
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
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.
Offline
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
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
I am using a tormtable result from MultiFieldValues
Can I have a little help more?
Thank you in advance
Offline
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
Pages: 1