Skip to content

Commit 3037950

Browse files
committed
Serialize Boolean
When delphi boolean type if json have no boolean type or string type will be error hgourvest/superobject#46
1 parent 7e73bcf commit 3037950

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Lib/superobject.pas

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ superobject.pas } // version: 2020.1213.1945
1+
{ superobject.pas } // version: 2020.1213.1955
22
(*
33
* Super Object Toolkit
44
*
@@ -2258,7 +2258,14 @@ function serialtoguid(ctx: TSuperRttiContext; var value: TValue; const index: IS
22582258
function serialfromboolean(ctx: TSuperRttiContext; const obj: ISuperObject; var Value: TValue): Boolean;
22592259
var
22602260
o: ISuperObject;
2261+
S: string;
22612262
begin
2263+
if obj = nil then // https://github.com/hgourvest/superobject/pull/46
2264+
begin
2265+
TValueData(Value).FAsSLong := Ord(False);
2266+
Result := True;
2267+
Exit;
2268+
end;
22622269
case ObjectGetType(obj) of
22632270
stBoolean:
22642271
begin
@@ -2275,7 +2282,20 @@ function serialfromboolean(ctx: TSuperRttiContext; const obj: ISuperObject; var
22752282
o := SO(obj.AsString);
22762283
if not ObjectIsType(o, stString) then
22772284
Result := serialfromboolean(ctx, SO(obj.AsString), Value) else
2278-
Result := False;
2285+
begin // https://github.com/hgourvest/superobject/pull/46
2286+
S := obj.AsString;
2287+
if (S = '1') or (S = '-1') or SameText(S, 'True') then
2288+
begin
2289+
TValueData(Value).FAsSLong := Ord(True);
2290+
Result := True;
2291+
end
2292+
else if (S = '0') or SameText(S, 'False') then
2293+
begin
2294+
TValueData(Value).FAsSLong := Ord(False);
2295+
Result := True;
2296+
end else
2297+
Result := False;
2298+
end;
22792299
end;
22802300
else
22812301
Result := False;
@@ -6709,9 +6729,7 @@ procedure TSuperArray.Insert(index: Integer; const value: ISuperObject);
67096729
if (index < FLength) then
67106730
begin
67116731
if FLength = FSize then
6712-
{+}
67136732
Expand(FLength+1); // https://github.com/hgourvest/superobject/pull/16
6714-
{+.}
67156733
if Index < FLength then
67166734
Move(FArray^[index], FArray^[index + 1],
67176735
(FLength - index) * SizeOf(Pointer));

0 commit comments

Comments
 (0)