Skip to content

Commit

Permalink
Serialize Boolean
Browse files Browse the repository at this point in the history
When delphi boolean type if json have no boolean type or string type will be error
hgourvest/superobject#46
  • Loading branch information
pult committed Dec 13, 2020
1 parent 7e73bcf commit 3037950
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Lib/superobject.pas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ superobject.pas } // version: 2020.1213.1945
{ superobject.pas } // version: 2020.1213.1955
(*
* Super Object Toolkit
*
Expand Down Expand Up @@ -2258,7 +2258,14 @@ function serialtoguid(ctx: TSuperRttiContext; var value: TValue; const index: IS
function serialfromboolean(ctx: TSuperRttiContext; const obj: ISuperObject; var Value: TValue): Boolean;
var
o: ISuperObject;
S: string;
begin
if obj = nil then // https://github.com/hgourvest/superobject/pull/46
begin
TValueData(Value).FAsSLong := Ord(False);
Result := True;
Exit;
end;
case ObjectGetType(obj) of
stBoolean:
begin
Expand All @@ -2275,7 +2282,20 @@ function serialfromboolean(ctx: TSuperRttiContext; const obj: ISuperObject; var
o := SO(obj.AsString);
if not ObjectIsType(o, stString) then
Result := serialfromboolean(ctx, SO(obj.AsString), Value) else
Result := False;
begin // https://github.com/hgourvest/superobject/pull/46
S := obj.AsString;
if (S = '1') or (S = '-1') or SameText(S, 'True') then
begin
TValueData(Value).FAsSLong := Ord(True);
Result := True;
end
else if (S = '0') or SameText(S, 'False') then
begin
TValueData(Value).FAsSLong := Ord(False);
Result := True;
end else
Result := False;
end;
end;
else
Result := False;
Expand Down Expand Up @@ -6709,9 +6729,7 @@ procedure TSuperArray.Insert(index: Integer; const value: ISuperObject);
if (index < FLength) then
begin
if FLength = FSize then
{+}
Expand(FLength+1); // https://github.com/hgourvest/superobject/pull/16
{+.}
if Index < FLength then
Move(FArray^[index], FArray^[index + 1],
(FLength - index) * SizeOf(Pointer));
Expand Down

0 comments on commit 3037950

Please sign in to comment.