Skip to content

Commit

Permalink
[serializer] separate interface
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Jul 8, 2020
1 parent 5282330 commit 8a63453
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Quick.Json.Serializer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface
SysUtils,
Rtti,
TypInfo,
Quick.Serializer.Intf,
{$IFDEF FPC}
rttiutils,
fpjson,
Expand Down Expand Up @@ -68,6 +69,8 @@ interface

type

IJsonSerializer = ISerializer;

EJsonSerializeError = class(Exception);
EJsonDeserializeError = class(Exception);

Expand Down Expand Up @@ -115,14 +118,6 @@ TJSONObjectHelper = class helper for Data.DBXJson.TJSONObject
{$ENDIF}
{$ENDIF}

IJsonSerializer = interface
['{CA26F7AE-F1FE-41BE-9C23-723A687F60D1}']
function JsonToObject(aType: TClass; const aJson: string): TObject; overload;
function JsonToObject(aObject: TObject; const aJson: string): TObject; overload;
function ObjectToJson(aObject : TObject; aIndent : Boolean = False): string;
function ValueToJson(const aValue : TValue; aIndent : Boolean = False) : string;
end;

TSerializeLevel = (slPublicProperty, slPublishedProperty);

TRTTIJson = class
Expand Down Expand Up @@ -709,6 +704,7 @@ function TRTTIJson.DeserializeProperty(aObject : TObject; const aName : string;
case aProperty.PropertyType.TypeKind of
tkDynArray :
begin
if member is TJSONNull then Exit;
{$IFNDEF FPC}
jArray := TJSONObject.ParseJSONValue(member.ToJSON) as TJSONArray;
{$ELSE}
Expand Down
24 changes: 24 additions & 0 deletions Quick.Serializer.Intf.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
unit Quick.Serializer.Intf;

interface

uses
System.SysUtils,
{$IFNDEF FPC}
rtti;
{$ELSE}
rttiutils;
{$ENDIF}

type
ISerializer = interface
['{CA26F7AE-F1FE-41BE-9C23-723A687F60D1}']
function JsonToObject(aType: TClass; const aJson: string): TObject; overload;
function JsonToObject(aObject: TObject; const aJson: string): TObject; overload;
function ObjectToJson(aObject : TObject; aIndent : Boolean = False): string;
function ValueToJson(const aValue : TValue; aIndent : Boolean = False) : string;
end;

implementation

end.

0 comments on commit 8a63453

Please sign in to comment.