TDateTime properties in TObject passed via rawInvoke to/from a XData Server

I'm using TXDataWebClient Invoking service operations from a XData Server (via RawInvokeAsync).
I’m passing a Delphi Object that has a TDateTime property. Unfortunately XData is serializing/deserializing TDateTime as a ISO 8601 Formated Date String (like ‘2021-08-02T12:30:59’) and WebCore is serializing the TDateTime as a unix timestamp.
Is there a way to tell the XData serializer or the WebCore serializer to be consistent with the other one?

I could also use a compiler directive like this:

TMyObject = Class
BirthDay: TSomeISO8601JsDateTime;
BirthDay: TDateTime;

But is there something like a TSomeISO8601JsDateTime?

For now it's up to you to create a proper JS object (TJSObject) that contains the data in the correct format expected by XData, which is in ISO 8601 format.
You can simply use a string type for that, and put the date in correct format. You can use BCL functions to do this:

uses Bcl.Utils;
  MyObject.ISODate := TBclUtils.DateTimeToISO(MyDate);

Thank you. Yes, that is what I will do. I see that there are other problems with “direct” serialization.
I hope when you are saying “For now”, that soon there will be a common serialization for webCore and XData so we can use exact (more or less) the same objects between those two. That would be great.

unfortunatelly, the following code fail on webCores

s: String;
dt: TDateTime;
s := '2021-08-04T23:05:48.016';
dt := TBclUtils.ISOToDate(s);
console.log('Failed to convert');

The DateTimeString is serialized that way from a XDataServer in a Service Contract

Please use ISOToDateTime, not ISOToDate.

That worked :) many thans

1 Like

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