Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

PODO object

 Post Reply Post Reply
Author
Piffer Claudio View Drop Down
New Member
New Member
Avatar

Joined: 24 Jan 2012
Posts: 13
Post Options Post Options   Quote Piffer Claudio Quote  Post ReplyReply Direct Link To This Post Topic: PODO object
    Posted: 12 Nov 2019 at 2:33pm
Hi,

I'm writing a service that doesn't use Aurelius but PODO objects. 

I have defined the TPatient and TPatientAdditionalData classes.

This is the interface:

type
  TPatientGender = (Male, Female, Unknown);

  TPatientAdditionalData = class;

  TPatient = class(TObject)
  private
    FName: string;
    FAge: Integer;
    FSurname: string;
    FGender: TPatientGender;
    FID: string;
    FPatientID: string;
    FPatientAdditionalData: TList< TPatientAdditionalData >;
    procedure SetAge(const Value: Integer);
    procedure SetGender(const Value: TPatientGender);
    procedure SetID(const Value: string);
    procedure SetName(const Value: string);
    procedure SetPatientID(const Value: string);
    procedure SetSurname(const Value: string);
    function GetPatientAdditionalData: TList< TPatientAdditionalData >;
  public
    procedure BeforeDestruction; override;

    property ID: string read FID write SetID;
    property Name: string read FName write SetName;
    property Surname: string read FSurname write SetSurname;
    property Gender: TPatientGender read FGender write SetGender;
    property Age: Integer read FAge write SetAge;
    property PatientID: string read FPatientID write SetPatientID;
    property PatientAdditionalData: TList< TPatientAdditionalData > read GetPatientAdditionalData;
  end;

  TPatientAdditionalData = class(TObject)
  private
    FReferedDoctorName: string;
    FAge: Integer;
    FQRCodeImage: TMemoryStream;
    FQRCodeDecoded: string;
    FGPSAddress: string;
    FLocalAddress: string;
    procedure SetAge(const Value: Integer);
    procedure SetGPSAddress(const Value: string);
    procedure SetLocalAddress(const Value: string);
    procedure SetQRCodeDecoded(const Value: string);
    procedure SetQRCodeImage(const Value: TMemoryStream);
    procedure SetReferedDoctorName(const Value: string);
  public
    property ReferedDoctorName: string read FReferedDoctorName write SetReferedDoctorName;
    property QRCodeImage: TMemoryStream read FQRCodeImage write SetQRCodeImage;
    property QRCodeDecoded: string read FQRCodeDecoded write SetQRCodeDecoded;
    property Age: Integer read FAge write SetAge;
    property GPSAddress: string read FGPSAddress write SetGPSAddress;
    property LocalAddress: string read FLocalAddress write SetLocalAddress;
  end;

All compile fine but when i call the Patient resource the server raise this exception;

"EJsonGeneratorNotFound with message "Could not find JSON Generator for type "NativeInt",

The problem is this property of the class TPatient:

 property PatientAdditionalData: TList< TPatientAdditionalData > read GetPatientAdditionalData;

which is a generic list of TPatientAdditionalData.

Where am I doing wrong?

Thank you very much and best regards







Back to Top
Piffer Claudio View Drop Down
New Member
New Member
Avatar

Joined: 24 Jan 2012
Posts: 13
Post Options Post Options   Quote Piffer Claudio Quote  Post ReplyReply Direct Link To This Post Posted: 12 Nov 2019 at 3:04pm
Hi again,

Sorry! The exception occurs when I call the SwaggerUI or the swagger.json. The call on the resource work fine. How can I "resolve" this problem? I need to the swagger interface

Best Regards
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2567
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2019 at 9:28pm
Hi Claudio,
I believe the problem is this field:

FQRCodeImage: TMemoryStream;

XData can't serialize such field. You must remove it from JSON using JsonIgnore attribute:

[JsonIgnore]
FQRCodeImage: TMemoryStream;


Back to Top
Piffer Claudio View Drop Down
New Member
New Member
Avatar

Joined: 24 Jan 2012
Posts: 13
Post Options Post Options   Quote Piffer Claudio Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2019 at 9:39pm
Hi Wagner

thank you for your answer!

I thought that the TStream class was treated as a binary value (like a blob field http://www.tmssoftware.biz/business/xdata/doc/web/blob_representation.html) and serialized in Base64. 

Is it possible to insert an attribute to manage this case?

Best Regards




Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2567
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 22 Nov 2019 at 2:28pm
Not in this case. To serialize binary values as base64 properties in a JSON object, you can use TArray<byte>.
Back to Top
Piffer Claudio View Drop Down
New Member
New Member
Avatar

Joined: 24 Jan 2012
Posts: 13
Post Options Post Options   Quote Piffer Claudio Quote  Post ReplyReply Direct Link To This Post Posted: 23 Nov 2019 at 9:39am
Yes you are right!!

Many thanks Wagner!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down