7
7
Author : Kike Pérez
8
8
Version : 1.12
9
9
Created : 21/05/2018
10
- Modified : 03/10 /2021
10
+ Modified : 27/12 /2021
11
11
12
12
This file is part of QuickLib: https://github.com/exilon/QuickLib
13
13
@@ -131,16 +131,18 @@ TRTTIJson = class
131
131
fUseBase64Stream : Boolean;
132
132
fUseNullStringsAsEmpty : Boolean;
133
133
function GetValue (aAddr: Pointer; aType: TRTTIType): TValue; overload;
134
+ { $IFDEF FPC}
134
135
function GetValue (aAddr: Pointer; aTypeInfo: PTypeInfo): TValue; overload;
136
+ { $ENDIF}
135
137
function IsAllowedProperty (aObject : TObject; const aPropertyName : string) : Boolean;
136
- function GetPropertyValue (Instance : TObject; const PropertyName : string) : TValue;
138
+ // function GetPropertyValue(Instance : TObject; const PropertyName : string) : TValue;
137
139
function GetPropertyValueFromObject (Instance : TObject; const PropertyName : string) : TValue;
138
140
{ $IFNDEF FPC}
139
141
function GetFieldValueFromRecord (const aValue : TValue; const FieldName : string) : TValue;
140
142
{ $ENDIF}
143
+ { $IFDEF FPC}
141
144
procedure SetPropertyValue (Instance : TObject; aPropInfo : PPropInfo; aValue : TValue); overload;
142
145
procedure SetPropertyValue (Instance : TObject; const PropertyName : string; aValue : TValue); overload;
143
- { $IFDEF FPC}
144
146
function FloatProperty (aObject : TObject; aPropInfo: PPropInfo): string;
145
147
function GetPropType (aPropInfo: PPropInfo): PTypeInfo;
146
148
procedure LoadSetProperty (aInstance : TObject; aPropInfo: PPropInfo; const aValue: string);
@@ -210,7 +212,7 @@ TJsonSerializer = class(TInterfacedObject,IJsonSerializer)
210
212
property UseEnumNames : Boolean read fUseEnumNames write SetUseEnumNames;
211
213
property UseJsonCaseSense : Boolean read fUseJsonCaseSense write SetUseJsonCaseSense;
212
214
property UseBase64Stream : Boolean read fUseBase64Stream write SetUseBase64Stream;
213
- property UseNullStringsAsEmpty : Boolean read fUseNullStringsAsEmpty write fUseNullStringsAsEmpty ;
215
+ property UseNullStringsAsEmpty : Boolean read fUseNullStringsAsEmpty write SetUseNullStringsAsEmpty ;
214
216
function JsonToObject (aType : TClass; const aJson: string) : TObject; overload;
215
217
function JsonToObject (aObject : TObject; const aJson: string) : TObject; overload;
216
218
function JsonStreamToObject (aObject : TObject; aJsonStream : TStream) : TObject;
@@ -463,6 +465,7 @@ function TRTTIJson.DeserializeStream(aObject: TObject; const aJson: TJSONValue):
463
465
finally
464
466
stream.Free;
465
467
end ;
468
+ Result := aObject;
466
469
end ;
467
470
468
471
constructor TRTTIJson.Create(aSerializeLevel : TSerializeLevel; aUseEnumNames : Boolean = True);
@@ -587,7 +590,7 @@ function TRTTIJson.DeserializeObject(aObject: TObject; const aJson: TJSONObject)
587
590
if IsGenericList(propvalue.AsObject) then DeserializeList(propvalue.AsObject,' List' ,TJSONObject(aJson.GetValue(propertyname)))
588
591
else Result := DeserializeProperty(Result,propertyname,rProp,aJson);
589
592
end
590
- else if IsGenericXArray(propvalue{ $IFNDEF NEXTGEN} .TypeInfo.Name { $ELSE} .TypeInfo.NameFld.ToString{ $ENDIF} ) then
593
+ else if IsGenericXArray(string( propvalue{ $IFNDEF NEXTGEN} .TypeInfo.Name { $ELSE} .TypeInfo.NameFld.ToString{ $ENDIF} ) ) then
591
594
begin
592
595
DeserializeXArray(Result,propvalue,rProp,propertyname,aJson);
593
596
end
@@ -1089,49 +1092,49 @@ function TRTTIJson.GetJsonPairByName(aJson: TJSONObject; const aName: string): T
1089
1092
Result := nil ;
1090
1093
end ;
1091
1094
1092
- function TRTTIJson.GetPropertyValue (Instance : TObject; const PropertyName : string) : TValue;
1093
- var
1094
- pinfo : PPropInfo;
1095
- begin
1096
- Result := nil ;
1097
- pinfo := GetPropInfo(Instance,PropertyName);
1098
- if pinfo = nil then raise EJsonSerializeError.CreateFmt(' Property "%s" not found!' ,[PropertyName]);
1099
- case pinfo.PropType^.Kind of
1100
- tkInteger : Result := GetOrdProp(Instance,pinfo);
1101
- tkInt64 : Result := GetInt64Prop(Instance,PropertyName);
1102
- tkFloat : Result := GetFloatProp(Instance,PropertyName);
1103
- tkChar : Result := Char(GetOrdProp(Instance,PropertyName));
1104
- { $IFDEF FPC}
1105
- tkWString : Result := GetWideStrProp(Instance,PropertyName);
1106
- tkSString,
1107
- tkAString,
1108
- { $ELSE}
1109
- tkWString,
1110
- { $ENDIF}
1111
- tkLString : Result := GetStrProp(Instance,pinfo);
1112
- { $IFDEF FPC}
1113
- tkEnumeration :
1114
- begin
1115
- if fUseEnumNames then Result := GetEnumName(pinfo.PropType,GetOrdProp(Instance,PropertyName))
1116
- else Result := GetOrdProp(Instance,PropertyName);
1117
- end ;
1118
- { $ELSE}
1119
- tkEnumeration :
1120
- begin
1121
- if fUseEnumNames then Result := GetEnumName(@pinfo.PropType,GetOrdProp(Instance,PropertyName))
1122
- else Result := GetOrdProp(Instance,PropertyName);
1123
- end ;
1124
- { $ENDIF}
1125
- tkSet : Result := GetSetProp(Instance,pinfo,True);
1126
- { $IFNDEF FPC}
1127
- tkClass :
1128
- { $ELSE}
1129
- tkBool : Result := Boolean(GetOrdProp(Instance,pinfo));
1130
- tkObject :
1131
- { $ENDIF} Result := GetObjectProp(Instance,pinfo);
1132
- tkDynArray : Result := GetDynArrayProp(Instance,pinfo);
1133
- end ;
1134
- end ;
1095
+ // function TRTTIJson.GetPropertyValue(Instance : TObject; const PropertyName : string) : TValue;
1096
+ // var
1097
+ // pinfo : PPropInfo;
1098
+ // begin
1099
+ // Result := nil;
1100
+ // pinfo := GetPropInfo(Instance,PropertyName);
1101
+ // if pinfo = nil then raise EJsonSerializeError.CreateFmt('Property "%s" not found!',[PropertyName]);
1102
+ // case pinfo.PropType^.Kind of
1103
+ // tkInteger : Result := GetOrdProp(Instance,pinfo);
1104
+ // tkInt64 : Result := GetInt64Prop(Instance,PropertyName);
1105
+ // tkFloat : Result := GetFloatProp(Instance,PropertyName);
1106
+ // tkChar : Result := Char(GetOrdProp(Instance,PropertyName));
1107
+ // {$IFDEF FPC}
1108
+ // tkWString : Result := GetWideStrProp(Instance,PropertyName);
1109
+ // tkSString,
1110
+ // tkAString,
1111
+ // {$ELSE}
1112
+ // tkWString,
1113
+ // {$ENDIF}
1114
+ // tkLString : Result := GetStrProp(Instance,pinfo);
1115
+ // {$IFDEF FPC}
1116
+ // tkEnumeration :
1117
+ // begin
1118
+ // if fUseEnumNames then Result := GetEnumName(pinfo.PropType,GetOrdProp(Instance,PropertyName))
1119
+ // else Result := GetOrdProp(Instance,PropertyName);
1120
+ // end;
1121
+ // {$ELSE}
1122
+ // tkEnumeration :
1123
+ // begin
1124
+ // if fUseEnumNames then Result := GetEnumName(@pinfo.PropType,GetOrdProp(Instance,PropertyName))
1125
+ // else Result := GetOrdProp(Instance,PropertyName);
1126
+ // end;
1127
+ // {$ENDIF}
1128
+ // tkSet : Result := GetSetProp(Instance,pinfo,True);
1129
+ // {$IFNDEF FPC}
1130
+ // tkClass :
1131
+ // {$ELSE}
1132
+ // tkBool : Result := Boolean(GetOrdProp(Instance,pinfo));
1133
+ // tkObject :
1134
+ // {$ENDIF} Result := GetObjectProp(Instance,pinfo);
1135
+ // tkDynArray : Result := GetDynArrayProp(Instance,pinfo);
1136
+ // end;
1137
+ // end;
1135
1138
1136
1139
function TRTTIJson.GetPropertyValueFromObject (Instance : TObject; const PropertyName : string) : TValue;
1137
1140
var
@@ -1156,6 +1159,7 @@ function TRTTIJson.GetFieldValueFromRecord(const aValue : TValue; const FieldNam
1156
1159
end ;
1157
1160
{ $ENDIF}
1158
1161
1162
+ { $IFDEF FPC}
1159
1163
procedure TRTTIJson.SetPropertyValue (Instance : TObject; const PropertyName : string; aValue : TValue);
1160
1164
var
1161
1165
pinfo : PPropInfo;
@@ -1192,7 +1196,6 @@ procedure TRTTIJson.SetPropertyValue(Instance : TObject; aPropInfo : PPropInfo;
1192
1196
end ;
1193
1197
end ;
1194
1198
1195
- { $IFDEF FPC}
1196
1199
procedure TRTTIJson.LoadSetProperty (aInstance : TObject; aPropInfo: PPropInfo; const aValue: string);
1197
1200
type
1198
1201
TCardinalSet = set of 0 ..SizeOf(Cardinal) * 8 - 1 ;
@@ -1298,7 +1301,7 @@ function TRTTIJson.SerializeObject(aObject: TObject): TJSONObject;
1298
1301
// end
1299
1302
if propvalue.IsObject then jpair.JsonValue := SerializeObject(propvalue.AsObject)
1300
1303
{ $IFNDEF FPC}
1301
- else if (not propvalue.IsObject) and (IsGenericXArray(propvalue{ $IFNDEF NEXTGEN} .TypeInfo.Name { $ELSE} .TypeInfo.NameFld.ToString{ $ENDIF} )) then
1304
+ else if (not propvalue.IsObject) and (IsGenericXArray(string( propvalue{ $IFNDEF NEXTGEN} .TypeInfo.Name { $ELSE} .TypeInfo.NameFld.ToString{ $ENDIF} ) )) then
1302
1305
begin
1303
1306
jpair.JsonValue := SerializeValue(GetFieldValueFromRecord(propvalue,' fArray' ));
1304
1307
end
@@ -1336,10 +1339,12 @@ function TRTTIJson.GetValue(aAddr: Pointer; aType: TRTTIType): TValue;
1336
1339
TValue.Make(aAddr,aType.Handle,Result);
1337
1340
end ;
1338
1341
1342
+ { $IFDEF FPC}
1339
1343
function TRTTIJson.GetValue (aAddr: Pointer; aTypeInfo: PTypeInfo): TValue;
1340
1344
begin
1341
1345
TValue.Make(aAddr,aTypeInfo,Result);
1342
1346
end ;
1347
+ { $ENDIF}
1343
1348
1344
1349
function TRTTIJson.SerializeValue (const aValue : TValue) : TJSONValue;
1345
1350
begin
@@ -1453,7 +1458,6 @@ function TRTTIJson.SerializeValue(const aValue : TValue) : TJSONValue;
1453
1458
function TRTTIJson.SerializeStream (aObject: TObject): TJSONValue;
1454
1459
var
1455
1460
stream : TStream;
1456
- json : string;
1457
1461
begin
1458
1462
Result := nil ;
1459
1463
try
0 commit comments