#1 2023-08-16 16:39:51

srclark71
Member
Registered: 2023-07-13
Posts: 5

ObjectToJSON problem

I am currently upgrading some projects to mORMot2 and have come across something that stopped working.  I can't really say why it was done this way and I have since made a workaround using just the TSQLJsonTable to read the data on the client side.  Any ideas as to why this doesn't work or if I maybe missed something?

  TSQLOrders = class(TOrmVirtualTableAutoID)


    aTable := TSQLTableJSON.Create('', JsonRecordSet);
    try
      newOrders := TSQLOrders.Create;
      try
        newOrders.FillPrepare(aTable);
        Result := ObjectToJSON(newOrders.FillTable);
      finally
        newOrders.Free;
      end;
    finally
      aTable.Free;
    end;
...
    Result = '{}'

Offline

#2 2023-08-16 16:58:48

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

Re: ObjectToJSON problem

Shouldn't ObjectToJson() over a FillTable result instance indeed return just {} because TOrmTableJson has no published property, so there is nothing to serialize?

Offline

#3 2023-08-16 17:06:18

srclark71
Member
Registered: 2023-07-13
Posts: 5

Re: ObjectToJSON problem

I apologize for not posting the complete definition of my TSQLOrders

  TSQLOrders = class(TOrmVirtualTableAutoID)
  private
    fOrderID: Integer;
    fPart_Number: RawUTF8;
    fOrderNumber: RawUTF8;
    fMoldSize: Integer;
    fState: RawUTF8;
    fWeight: Double;
  published
    property OrderID: Integer read fOrderID write fOrderID;
    property OrderNumber: UTF8String read fOrderNumber write fOrderNumber;
    property State: UTF8String read fState write fState;
    property Part_Number: UTF8String read fPart_Number write fPart_Number;
    property Weight: Double read fWeight write fWeight;
    property MoldSize: Integer read fMoldSize write fMoldSize;
  end;

Offline

#4 2023-08-16 18:43:03

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

Re: ObjectToJSON problem

Why use ObjectToJson() here?

Why not just call the TOrmTableAbstract.GetJsonValues method?

Offline

#5 2023-08-16 20:10:36

srclark71
Member
Registered: 2023-07-13
Posts: 5

Re: ObjectToJSON problem

Not sure why the original code was written the way it was. I will go with that approach. 

Thank you

Offline

Board footer

Powered by FluxBB