Skip to content

Commit 34a3f59

Browse files
committed
Json.Helper fixed
1 parent 59a2acb commit 34a3f59

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

Quick.JSON.Helper.pas

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{ ***************************************************************************
22
3-
Copyright (c) 2015-2018 Kike Pérez
3+
Copyright (c) 2015-2020 Kike Pérez
44
55
Unit : Quick.JSON.Helper
66
Description : Utils for working with JSON
77
Author : Kike Pérez
88
Version : 1.1
99
Created : 27/01/2017
10-
Modified : 09/05/2018
10+
Modified : 16/01/2020
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -36,17 +36,7 @@ interface
3636
uses
3737
Classes,
3838
SysUtils,
39-
{$IFDEF DELPHIRX102_UP}
40-
JSON.Types,
41-
REST.Json,
42-
System.JSON,
43-
JSON.Serializers,
44-
{$ELSE}
45-
System.JSON,
46-
REST.JSON,
47-
Rest.Json.Types,
48-
{$ENDIF}
49-
Quick.Json.Utils;
39+
Quick.Json.Serializer;
5040

5141
type
5242
TObjectHelper = class helper for TObject
@@ -65,39 +55,32 @@ TObjectHelper = class helper for TObject
6555
implementation
6656

6757
function TObjectHelper.ToJSON : string;
68-
{$IFDEF DELPHIRX102_UP}
6958
var
70-
Serializer : TJsonSerializer;
71-
{$ENDIF}
59+
Serializer : TJsonSerializer;
7260
begin
7361
Result := '';
7462
try
75-
{$IFDEF DELPHIRX102_UP}
76-
Serializer := TJsonSerializer.Create;
77-
try
78-
if GlobalJsonIdenter then Serializer.Formatting := TJsonFormatting.Indented;
79-
Result := Serializer.Serialize<TObject>(Self);
80-
finally
81-
Serializer.Free;
82-
end;
83-
{$ELSE}
84-
Result := TJson.ObjectToJsonString(Self);
85-
{$ENDIF}
63+
Serializer := TJsonSerializer.Create(TSerializeLevel.{$IFDEF FPC}slPublishedProperty{$ELSE}slPublicProperty{$ENDIF},True);
64+
try
65+
Result := Serializer.ObjectToJson(Self,GlobalJsonIdenter);
66+
finally
67+
Serializer.Free;
68+
end;
8669
except
8770
on e : Exception do raise Exception.Create(e.Message);
8871
end;
8972
end;
9073

9174
procedure TObjectHelper.FromJson(const json :string);
9275
var
93-
jObj : TJSONObject;
76+
Serializer : TJsonSerializer;
9477
begin
9578
try
96-
jObj := TJSonObject.ParseJSONValue(json,true) as TJSONObject;
79+
Serializer := TJsonSerializer.Create(TSerializeLevel.{$IFDEF FPC}slPublishedProperty{$ELSE}slPublicProperty{$ENDIF},True);
9780
try
98-
TJson.JsonToObject(self,jObj);
81+
Serializer.JsonToObject(Self,json);
9982
finally
100-
jObj.Free;
83+
Serializer.Free;
10184
end;
10285
except
10386
on e : Exception do raise Exception.Create(e.Message);

0 commit comments

Comments
 (0)