#1 2022-11-29 11:35:08

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Datetime should not be empty

I Receive TObjects from my Server via SOA Interface.
The Object contains TDateTime Fields.
One of these date fields is null (0)

On the Client site these Objects are Create by RTTI calls in mORMot2.
I got an error if DateField = 0

As Patch i modified mormot.core.rtti.pas Line 3884f:

      f := _Iso8601ToDateTime(u);
//      if f = 0 then   // itSDS Datetime kann leer sein wenn es "Null" auf dem Server ist.
//        exit;
      SetFloatProp(Instance, f);
    end

Can you add this to the Repo - if my Patch is right ?


Rad Studio 12.1 Santorini

Offline

#2 2022-11-29 13:54:17

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

Re: Datetime should not be empty

What is the input Value?

If it is null, then VariantToDouble(Value, f) is true, and f = 0.
So it does not go into the line you quoute.

Offline

#3 2022-11-29 16:51:22

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Datetime should not be empty

I debugged the lines and the input Value is "" (Empty String) for the DateTime Property.
What i'm wondering about is that the parser calls different property parser for my DateTime property.
In case of my "ausgabedatum" Property it calls procedure TJsonParserContext.ParsePropComplex(Data: pointer);
And for one of my other DateTime Property "GeloeschtAm" it calls procedure _JL_DateTime(Data: PDateTime; var Ctxt: TJsonParserContext); the Value is in both Cases = ""

The Error displayed is:

EInterfaceFactory mit Meldung 'IDomV.GetG failed parsing AArray: TArray<DomVTypes.TGObject> from input JSON'. Prozess xyz.exe (1312) (Generated in mormot.core.interfaces line 2665)

Last edited by itSDS (2022-11-29 16:55:13)


Rad Studio 12.1 Santorini

Offline

#4 2022-11-29 18:06:43

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

Re: Datetime should not be empty

I still don't get it.
_JL_DateTime() with a void string as input can not make any error.

What is the JSON at that time?

Offline

#5 2022-11-29 19:53:48

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Datetime should not be empty

There is 1 difference: property ausgabedatum has a setter defined (setausgabedatum) then _JL_DateTime is not called but Ctxt.ParsePropComplex because Prop^.OffsetSet = -1 and ParsePropComplex calls my Patched TRttiProp.SetValue which tries to set my Ausgabedatum to "" -> resulting in an error.

and here is the json:

...
Vertrag:null,Standrohr:{ServerState:4,Anlagedatum:"2022-11-26T09:15:25",LetzteAenderung:"2022-11-26T09:15:25",GeloeschtAm:"",GeraetID:1916,Mandant:null,Geraetetyp:null,Kontrolle:null,Vertrag:null,Standrohr:null,Status:0,Lagerort:"",Seriennummer:"",Baujahr:0,Hersteller:"",Beschreibung:"",Identifikation:"",Notiz:"",Groesse:"",Bauform:"",Eichjahr:0,NextEichjahr:0,Zaehlerstand:0,Ausgabedatum:""},Status
...

Rad Studio 12.1 Santorini

Offline

#6 2022-11-29 19:54:51

tbo
Member
Registered: 2015-04-20
Posts: 353

Re: Datetime should not be empty

Instead of using this argument "AArray: TArray<DomVTypes.TGObject>" in the interface definition of the function, have you tried it this way "out AArray: TGObjectObjArray"?

type
  TGObjectObjArray = array of DomVTypes.TGObject;

initialization
  Rtti.RegisterObjArrays([TypeInfo(TGObjectObjArray), DomVTypes.TGObject]);

With best regards
Thomas

Offline

#7 2022-11-29 19:58:24

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Datetime should not be empty

example for the TObject i use as parameter:

TBaseObject = class(TObject)
private
  fAnlagedatum : TDateTime;
..
published
  property Anlagedatum : TDateTime read fAnlagedatum;
end;

TDerivedObject = class(TBaseClass)
protected
  fAusgabedatum : TDateTime;
private
  procedure SetAusgabedatum(const AAusgabedatum : TDateTime);
published
  property Ausgabedatum : TDateTime read fAusgabedatum write SetAusgabedatum;

Last edited by itSDS (2022-11-29 19:58:44)


Rad Studio 12.1 Santorini

Offline

#8 2022-11-29 20:02:12

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Datetime should not be empty

@tbo

My Real Interface looks like this:

  TDObjArray = TArray<TDerivedObject >;

  IDomGverwaltung = interface(IInvokable) 
..
  function GetDerived(out ADerived : TDObjArray) : TresultRec;
..
  TInterfaceFactory.RegisterInterfaces([TypeInfo(IDomGverwaltung)]);

Last edited by itSDS (2022-11-29 20:03:23)


Rad Studio 12.1 Santorini

Offline

#9 2022-11-30 08:52:54

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

Re: Datetime should not be empty

Great!

Now, I understand.
Please try https://github.com/synopse/mORMot2/commit/00ed9a34

Offline

#10 2022-11-30 16:49:24

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Datetime should not be empty

Thank - that's it smile


Rad Studio 12.1 Santorini

Offline

Board footer

Powered by FluxBB