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
Public
{$IFDEF PAS2JS}
BirthDay: TSomeISO8601JsDateTime;
{$ELSE}
BirthDay: TDateTime;
{$ENDIF}
End;
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:
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
Var
s: String;
dt: TDateTime;
Begin
Try
s := '2021-08-04T23:05:48.016';
dt := TBclUtils.ISOToDate(s);
console.log(dt);
Except
console.log('Failed to convert');
End;
The DateTimeString is serialized that way from a XDataServer in a Service Contract