Serializer Json missing properties

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

That's how it is, the serializer adds those properties as metadata.
The reason on you don't get Id and Name properties is because your class is declared in dpr. Declare it in a separate unit and it will work ok.

Thank you.

I found out what's going on with my application. In this same example, when I add the attribute [Model ('Services')] to the entity, the behavior originally pointed out happens, even in a separate unit.

But, I realized that when I add [Model ('Default')] together with [Model ('Services')] the problem goes away.

1 Like