#1 2018-09-18 15:59:02

HeartWare
Member
Registered: 2018-09-18
Posts: 1

JSON streaming

I have just begun using mORMot to stream RECORDs into and out of JSON strings using the RecordSaveJSON and RecordLoadJSON functions.

I have a couple of things that I would like to do, but can't figure out how. I have some fields in my RECORD that's another name than I want it to be represented with in the JSON file (the name in the JSON file is not my doing, but it is an illegal identifier name in a RECORD).

In my own routines that uses RTTI to parse the record, I have an attribute "FieldName" that I can attach to the RECORD field in order to signal that the external name is different from the internal name. Is there some way to accomplish this using mORMot? Preferably by using attributes, but I seem to have read that mORMot doesn't use attributes - this is actually a very nice way to implement this feature, as it will only be used in the case where there's a discrepancy between the internal name and the external name. Perhaps using a custom text writer (but how does that work)?

Also, I can see that the RecordSaveJSON and RecordLoadJSON has support for TDateTime types to be mapped to a date string, but for some reason it doesn't handle TDate (for a date-only time stamp) or TTime (for a time-only time stamp). Would it be possible to implement these? I tried doing it myself in SynCommons (where there's an array that maps the Pascal Type Name to some internal enumeration), but my changes caused some exception to occur at startup, so I undid it again.

Last edited by HeartWare (2018-09-18 15:59:24)

Offline

#2 2018-09-20 08:38:33

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: JSON streaming

See documentation `10.1.3. Record serialization` specifically `10.1.3.2.2. Custom serialization`.

If it supports TDateTime it supports TDate and TTime. If you don't need ms resolution it is prefered to use TTimeLog.

Offline

Board footer

Powered by FluxBB