PODO object

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







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
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;


Reference: http://www.tmssoftware.com/business/xdata/doc/web/including_json_properties.html

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




Not in this case. To serialize binary values as base64 properties in a JSON object, you can use TArray<byte>.

Yes you are right!!


Many thanks Wagner!