Hello
I'm starting the migration of our software to Delphi 12, and after updating Aurelius (v5.17.0), I detected some problems in the TDataSnapJsonSerializer class.
Apparently, properties of type integer are not serialized in the correct way.
For the following entity
type
[Entity]
[Table('Product')]
[Description('Produto')]
[Sequence('Id_Product')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TProduct = class
private
[Column('Id', [TColumnProp.Required])]
[Description('')]
FId: Integer;
[Column('Description', [TColumnProp.Required], 30)]
[Description('')]
FDescription: string;
[Column('Price', [TColumnProp.Required])]
[Description('')]
FPrice: Double;
public
property Id: Integer read FId write FId;
property Description: string read FDescription write FDescription;
property Price: Double read FPrice write FPrice;
end;
I created an instance FProduct
FProduct := TProduct.Create;
FProduct.Id := 1;
FProduct.Description := 'Bread';
FProduct.Price := 0.25;
Then I serialized the FProduct object, using the ToJson function
procedure Serialize;
var
FSerializer: TDataSnapJsonSerializer;
FJsonValue : TJsonValue;
begin
FSerializer := TDataSnapJsonSerializer.Create;
FJsonValue := FSerializer.ToJson(FProduct);
mmLog.Text := FJsonValue.ToString;
end;
The result of FJsonValue.ToString is
{"$type":"ufrmJsonTest.TProduct","$id":1.0,"FPrice":0.25,"FDescription":"Bread","FId":1.0}
As you can see, the FId property is displayed to decimal places.
When I try to deserialize this json, an exception is returned
procedure TfrmJsonTest.Deserialize;
var
FDeserializer: TDataSnapJsonDeserializer;
ftmpproduct : TProduct;
begin
FDeserializer := TDataSnapJsonDeserializer.Create;
try
ftmpproduct := FDeserializer.FromJson<TProduct>(FJsonValue);
except
on E : Exception do
begin
mmLog.Text := E.Message;
end;
end;
end;
//Incompatible json value. Cannot serialize to the proper type.
//(Integer): Expected JSON String or Integer
I hope that all above is clear... Thanks in advance!