Hello, I'm trying to serialize an object TPerson to json using TDataSnapJsonSerializer, this entity has only two properties Id and Name, but the result that I get from serializer is the following:
{"$type":"JsonSerialize.TPerson","$id":1}, what am I doing wrong?
Minimum Reproducible Example:
program JsonSerialize;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.JSON,
Aurelius.Mapping.Attributes,
Aurelius.Json.Datasnap;
type
[Entity]
[Table('Person')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TPerson = class
private
[Column('Id', [TColumnProp.Required])]
FId: integer;
[Column('Name', [TColumnProp.Required], 50)]
FName: string;
public
property Id: integer read FId write FId;
property Name: string read FName write FName;
end;
procedure SerializerTest(APerson: TPerson);
begin
var Serializer := TDataSnapJsonSerializer.Create;
try
var JsonValue := Serializer.ToJson(APerson);
try
WriteLn('json: ');
WriteLn(JsonValue.ToString);
finally
JsonValue.Free;
end;
ReadLn;
finally
Serializer.Free;
end;
end;
begin
ReportMemoryLeaksOnShutDown := True;
try
RegisterEntity(TPerson);
var LPerson := TPerson.Create;
try
LPerson.Id := 1;
LPerson.Name := 'John Doe';
SerializerTest(LPerson);
finally
LPerson.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Versions:
Delphi 10.4 Patch 3
TMS Business Core Library 1.22.0.0
TMS Aurelius 4.17.2.0