#1 2019-09-12 10:10:19

MrWaz
Member
Registered: 2019-08-13
Posts: 4

SOA & Cross Platform clients - inconsistency in TDateTime parameters

Hello,

We're using mORMot since 2~3 years in our applications mainly for the services via interfaces feature.

I noticed what looks like an inconsistency in parameters serialization when using cross platform units.

- The server is a vcl windows service using regular mormot units
- The client is a firemonkey application using the cross-plaform dedicated ones.

I'm exchanging complex objects structures containing TDateTime fields without any issue but yesterday I had to define some TDateTime parameter in a method definition. 

    IMyService = interface(IInvokable)
        procedure MyProc(const inSomeTime: TDateTime);
    end;

Calling this method from my fmx client, I received some 406 error indicating that the parameter  'inSomeTime' was missing.
The parameter is serialized as a string in cross platform units, when it's expected as a number in regular mormot units.

If I replace the TDateTime by a simple record, it works just fine.

TMyTime = packed record
   Value : TDateTime;
end;

I worked around the issue but wanted to let you know, hoping I'll be able to remove my workaround some day.

Thanks for all your great work

Sylvain

---
PS : by the way, latest rev of SynCrossPlatformREST does not compile on windows.

Offline

#2 2019-09-13 01:31:35

Peter Evans
Member
Registered: 2016-07-03
Posts: 32

Re: SOA & Cross Platform clients - inconsistency in TDateTime parameters

Is your FMX client running on Windows or Android?

For my coding where the FMX client runs on both Windows and Android the only fail safe way of passing a date as a parameter is to convert it into a string. Then pass the string as a parameter.

Offline

#3 2019-09-13 12:46:10

MrWaz
Member
Registered: 2019-08-13
Posts: 4

Re: SOA & Cross Platform clients - inconsistency in TDateTime parameters

Hi Peter

I've clients on both windows and android..

Your solution is precisely what I call a workaround wink

Note that when using TDateTime into classes or records, TDateTime fields are consistently serialized as strings.. it perfectly works on both android and windows.. 

As you say, TDateTime to string automatic serialization using ISO 8601 standard is the only fail safe way of handling dates as it allows interoperability with non-delphi clients.
In our ecosystem, we also have some java servlets and even native android applications consuming our mormot web services. 

So probably the proper question is :
Why do syncommon & mormot units serialize TDateTime as numbers when used as interface method parameters as it seems to be handled as strings everywhere else?

All the best

Sylvain

Last edited by MrWaz (2019-09-17 07:17:57)

Offline

#4 2019-09-13 16:01:06

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

Re: SOA & Cross Platform clients - inconsistency in TDateTime parameters

You are right.
TDateTime as number sounds like a bug/inconsistency.

Please check https://synopse.info/fossil/info/187d474624
SOA TDateTime parameters will now be serialized as ISO8601 JSON text instead of unusual TDateTime JSON number.

Warning: this is a BREAKING CHANGE !
But it shouldn't affect too much existing applications, since previous implementation was somewhat inconsistent, especially with the cross-platform clients.
If you want the TDateTime to be serialized as number, just define the parameter as "double" instead of TDateTime.

Offline

#5 2019-09-17 07:24:15

MrWaz
Member
Registered: 2019-08-13
Posts: 4

Re: SOA & Cross Platform clients - inconsistency in TDateTime parameters

Many Thanks

We're back with TDateTime parameters and it works like a charm

Long live the mORMot!

All the best

Sylvain

Offline

Board footer

Powered by FluxBB