Problem on TDataSnapJsonSerializer - MacOS

Hello

Some time ago, I reported this error in the TDataSnapJsonSerializer class, and it was resolved in version 5.17.3 for windows, but the error persists on macOS.

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!

Sorry, cannot reproduce. Below is the full code I used.
Probably you didn't rebuild for macOS? If using Smart Setup, just run tms build -full.

unit Unit3;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.JSON,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls,
  Bcl.Json, Bcl.Json.Classes, Bcl.Json.Serializer, Aurelius.Json.DataSnap, Aurelius.Json.Interfaces,
  Aurelius.Mapping.Attributes, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo;

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;

  TForm3 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    FProduct: TProduct;
    procedure Serialize;
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.fmx}

procedure TForm3.Serialize;
var
  FSerializer: TDataSnapJsonSerializer;
  FJsonValue: TJsonValue;
begin
  FSerializer := TDataSnapJsonSerializer.Create;
  FJsonValue := FSerializer.ToJson(FProduct);
  Memo1.Text := FJsonValue.ToString;
end;

procedure TForm3.Button1Click(Sender: TObject);
begin
  FProduct := TProduct.Create;
  FProduct.Id := 1;
  FProduct.Description := 'Bread';
  FProduct.Price := 0.25;
  Serialize;
end;

end.

Hi,
I've reinstalled the versions of aurelius, recompiled the project and the same error still occurs. I'm testing on a MacBook Pro (macOS Sonoma 14.2.1).

I can see that when the Id is serialized, the function TDataSnapJsonFactory.CreateNumber(D: double): IJsonValue is executed in the Aurelius.Json.DataSnap class.
Somewhere in the code, the Id of type Integer is seen as a Double...

The same code, in windows, calls the function TDataSnapJsonFactory.CreateInteger(I: Integer): IJsonValue;.

I tested the code compiled for macOS 64-bit and macOS ARM 64-bit. Both have the same problem.

JsonTest.zip (9.7 KB)

I've attached my sample.

Thank you

Sorry, your project works fine here. Tried on macOS64ARM platform.
Try to uninstall everything. delete all leftovers in your library path, search remaining files Aurelius*.dcu, Aurelius.*.pas, aurelius*.dcp in your hard disk, delete them all, and reinstall, preferable using TMS Smart Setup.

After uninstalling everything again and deleting the files, it worked!

Thanks for your help

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.