#1 2014-05-13 02:03:07

avista
Member
Registered: 2014-01-06
Posts: 63

Bug In Record De-Serialization of Currency Type

In the code below:

Rec.Curr is set to 100 and is serialized correctly:

Json1 =  '{"Id":55,"Name":"This is the name.","Curr":100}'

However, it is de-serialized incorrectly in the call to

    RecordLoadJSON(Rec, @Json1Copy[1], TypeInfo(TTestRec));

Rec.Curr =  1000000

Json2 = '{"Id":55,"Name":"This is the name.","Curr":1000000}'

program JsonBug;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  SynCommons;

type
  TTestRec = packed record
    Id: Integer;
    Name: string;
    Curr: Currency;
  end;

const
  __TTestRec = 'Id: Integer; Name: string; Curr: Currency;';

var
  Rec: TTestRec;
  Json1, Json1Copy, Json2: RawUTF8;
begin
  try
    Rec.Id := 55;
    Rec.Name := 'This is the name.';
    Rec.Curr := 100;

    TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TTestRec), __TTestRec);
    Json1 := RecordSaveJSON(Rec, TypeInfo(TTestRec));
    Json1Copy := Json1;
    Rec := Default(TTestRec);

    RecordLoadJSON(Rec, @Json1Copy[1], TypeInfo(TTestRec));
    Json2 := RecordSaveJSON(Rec, TypeInfo(TTestRec));

    Assert(SameTextU(Json1, Json2));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Sorry for the recent bug reports. sad

Offline

#2 2014-05-13 06:16:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: Bug In Record De-Serialization of Currency Type

Oups... there was indeed an issue!

We have just fixed an issue in record de-serialization of Currency type.
See http://synopse.info/fossil/info/bb7df90946

Thanks a lot for the feedback!

Offline

Board footer

Powered by FluxBB