Skip to content

Commit 4a25c05

Browse files
committed
https://github.com/danieleteti/delphimvcframework/issues/590
1 parent b1f838e commit 4a25c05

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,8 @@ The current beta release is named 3.2.3-radium-beta. If you want to stay on the-
14881488
#### Bug Fix in 3.2.3-radium-beta
14891489
- Fixed a rendering problem in swagger interface format in case of specific JSON structure
14901490
- Fix [issue 594](https://github.com/danieleteti/delphimvcframework/issues/594) (Thanks to [biware-repo](https://github.com/biware-repo))
1491+
- Fix [issue 595](https://github.com/danieleteti/delphimvcframework/issues/595)
1492+
- Fix [issue 590](https://github.com/danieleteti/delphimvcframework/issues/590)
14911493

14921494

14931495
## Trainings, consultancy or custom development service

sources/MVCFramework.JSONRPC.pas

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ interface
4040
System.Rtti,
4141
System.Generics.Collections,
4242
MVCFramework.Serializer.Commons,
43-
MVCFramework.Serializer.JsonDataObjects, System.SysUtils;
43+
MVCFramework.Serializer.JsonDataObjects,
44+
System.SysUtils;
4445

4546
const
4647
JSONRPC_VERSION = '2.0';
@@ -459,6 +460,11 @@ TJSONRPCProxyGenerator = class abstract
459460

460461
TJSONRPCProxyGeneratorClass = class of TJSONRPCProxyGenerator;
461462

463+
TJSONUtilsHelper = record helper for TJSONUtils
464+
class function JSONObjectToRecord<T: record >(const JSONRPCResponse: IInterface): T; overload; static;
465+
class function JSONArrayToArrayOfRecord<T: record >(const JSONRPCResponse: IInterface): TArray<T>; overload; static;
466+
end;
467+
462468
procedure RegisterJSONRPCProxyGenerator(const aLanguage: string; const aClass: TJSONRPCProxyGeneratorClass);
463469

464470
implementation
@@ -2813,6 +2819,38 @@ constructor EMVCJSONRPCRemoteException.Create(const ErrCode: Integer; const ErrM
28132819
fErrMessage := ErrMessage;
28142820
end;
28152821

2822+
{ TJSONUtilsHelper }
2823+
2824+
class function TJSONUtilsHelper.JSONArrayToArrayOfRecord<T>(
2825+
const JSONRPCResponse: IInterface): TArray<T>;
2826+
var
2827+
lIntf: IJSONRPCResponse;
2828+
begin
2829+
if Supports(JSONRPCResponse, IJSONRPCResponse, lIntf) then
2830+
begin
2831+
Result := TJSONUtils.JSONArrayToArrayOfRecord<T>(lIntf.ResultAsJSONArray);
2832+
end
2833+
else
2834+
begin
2835+
RaiseSerializationError('Parameter doesn''t support IJSONRPCResponse');
2836+
end;
2837+
end;
2838+
2839+
class function TJSONUtilsHelper.JSONObjectToRecord<T>(
2840+
const JSONRPCResponse: IInterface): T;
2841+
var
2842+
lIntf: IJSONRPCResponse;
2843+
begin
2844+
if Supports(JSONRPCResponse, IJSONRPCResponse, lIntf) then
2845+
begin
2846+
Result := TJSONUtils.JSONObjectToRecord<T>(lIntf.ResultAsJSONObject);
2847+
end
2848+
else
2849+
begin
2850+
RaiseSerializationError('Parameter doesn''t support IJSONRPCResponse');
2851+
end;
2852+
end;
2853+
28162854
initialization
28172855

28182856
finalization

sources/MVCFramework.Serializer.JsonDataObjects.pas

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ TJSONUtils = record
240240
public
241241
// records
242242
class function JSONObjectToRecord<T: record >(const JSONObject: TJsonObject): T; overload; static;
243-
class function JSONObjectToRecord<T: record >(const JSONRPCResponse: IInterface): T; overload; static;
244243
class function JSONArrayToArrayOfRecord<T: record >(const JSONArray: TJsonArray): TArray<T>; overload; static;
245-
class function JSONArrayToArrayOfRecord<T: record >(const JSONRPCResponse: IInterface): TArray<T>; overload; static;
246244
// objects
247245
class function JsonObjectToObject<T: class, constructor>(const JSONObject: TJsonObject): T; overload; static;
248246
class function JSONArrayToListOf<T: class, constructor>(const JSONArray: TJsonArray): TObjectList<T>;
@@ -266,7 +264,6 @@ implementation
266264

267265
uses
268266
MVCFramework.Serializer.JsonDataObjects.CustomTypes,
269-
MVCFramework.JSONRPC,
270267
MVCFramework.Logger,
271268
MVCFramework.DataSet.Utils,
272269
MVCFramework.Nullables;
@@ -3951,20 +3948,6 @@ class function TJSONUtils.JSONArrayToArrayOfRecord<T>(const JSONArray: TJsonArra
39513948
end;
39523949
end;
39533950

3954-
class function TJSONUtils.JSONArrayToArrayOfRecord<T>(const JSONRPCResponse: IInterface): TArray<T>;
3955-
var
3956-
lIntf: IJSONRPCResponse;
3957-
begin
3958-
if Supports(JSONRPCResponse, IJSONRPCResponse, lIntf) then
3959-
begin
3960-
Result := TJSONUtils.JSONArrayToArrayOfRecord<T>(lIntf.ResultAsJSONArray);
3961-
end
3962-
else
3963-
begin
3964-
RaiseSerializationError('Parameter doesn''t support IJSONRPCResponse');
3965-
end;
3966-
end;
3967-
39683951
class function TJSONUtils.JSONArrayToListOf<T>(const JSONArray: TJsonArray): TObjectList<T>;
39693952
var
39703953
I: Integer;
@@ -4006,20 +3989,6 @@ class function TJSONUtils.JsonObjectToObject<T>(const JSONObject: TJsonObject):
40063989
end;
40073990
end;
40083991

4009-
class function TJSONUtils.JSONObjectToRecord<T>(const JSONRPCResponse: IInterface): T;
4010-
var
4011-
lIntf: IJSONRPCResponse;
4012-
begin
4013-
if Supports(JSONRPCResponse, IJSONRPCResponse, lIntf) then
4014-
begin
4015-
Result := TJSONUtils.JSONObjectToRecord<T>(lIntf.ResultAsJSONObject);
4016-
end
4017-
else
4018-
begin
4019-
RaiseSerializationError('Parameter doesn''t support IJSONRPCResponse');
4020-
end;
4021-
end;
4022-
40233992
class function TJSONUtils.JSONObjectToRecord<T>(const JSONObject: TJsonObject): T;
40243993
var
40253994
lSer: TMVCJsonDataObjectsSerializer;

sources/MVCFramework.pas

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ interface
5757
MVCFramework.ApplicationSession,
5858
MVCFramework.Serializer.Intf,
5959

60-
{$IFDEF WEBAPACHEHTTP}
60+
{$IF Defined(WEBAPACHEHTTP)}
6161
Web.ApacheHTTP,
6262
// Apache Support since XE6 http://docwiki.embarcadero.com/Libraries/XE6/de/Web.ApacheHTTP
6363

@@ -66,7 +66,7 @@ interface
6666
// Delphi XE4 (all update) and XE5 (with no update) don't contains this unit. Look for the bug in QC
6767
// https://quality.embarcadero.com/browse/RSP-17216
6868

69-
{$IFNDEF MOBILE} // file upload is not supported on mobile
69+
{$IF NOT Defined(MOBILE)} // file upload is not supported on mobile
7070
{$IF Defined(SeattleOrBetter)}
7171
Web.ReqMulti,
7272
{$ELSE}
@@ -75,14 +75,13 @@ interface
7575
{$ENDIF}
7676
Web.HTTPApp,
7777

78-
{$IFDEF MSWINDOWS}
78+
{$IF Defined(MSWINDOWS)}
7979
Web.Win.IsapiHTTP,
8080
{$ENDIF}
8181
Web.WebReq,
8282
LoggerPro,
8383
IdGlobal,
8484
IdGlobalProtocols,
85-
// IdHTTPWebBrokerBridge,
8685
Swag.Doc,
8786
Swag.Common.Types,
8887
MVCFramework.Commons,
@@ -425,7 +424,7 @@ TMVCWebRequest = class
425424
property Files: TAbstractWebRequestFiles read GetFiles;
426425
end;
427426

428-
{$IFDEF WEBAPACHEHTTP}
427+
{$IF Defined(WEBAPACHEHTTP)}
429428

430429
TMVCApacheWebRequest = class(TMVCWebRequest)
431430
private
@@ -1301,7 +1300,7 @@ function TMVCWebRequest.Body: string;
13011300
lEncoding := TEncoding.GetEncoding(lCurrCharset);
13021301
try
13031302

1304-
{$IFDEF BERLINORBETTER}
1303+
{$IF Defined(BERLINORBETTER)}
13051304
FWebRequest.ReadTotalContent; // Otherwise ISAPI Raises "Empty BODY"
13061305
FBody := lEncoding.GetString(FWebRequest.RawContent);
13071306
{$ELSE}
@@ -1977,20 +1976,20 @@ constructor TWebContext.Create(const ARequest: TWebRequest; const AResponse: TWe
19771976
end
19781977
else
19791978
begin
1980-
{$IFDEF WEBAPACHEHTTP}
1979+
{$IF Defined(WEBAPACHEHTTP)}
19811980
if ARequest.ClassType = TApacheRequest then
19821981
begin
19831982
FRequest := TMVCApacheWebRequest.Create(ARequest, ASerializers)
19841983
end
19851984
else
1986-
{$IFNDEF LINUX}
1985+
{$IF Defined(MSWINDOWS)}
19871986
if ARequest.ClassType = TISAPIRequest then
19881987
begin
19891988
FRequest := TMVCISAPIWebRequest.Create(ARequest, ASerializers)
19901989
end
19911990
else
1992-
{$ENDIF}
1993-
{$ENDIF}
1991+
{$ENDIF} //MSWINDOWS
1992+
{$ENDIF} //WEBAPACHEHTTP
19941993
begin
19951994
FRequest := TMVCIndyWebRequest.Create(ARequest, ASerializers);
19961995
end;
@@ -2044,13 +2043,13 @@ function TWebContext.GetData: TMVCStringDictionary;
20442043

20452044
function TWebContext.GetHostingFrameworkType: TMVCHostingFrameworkType;
20462045
begin
2047-
{$IFDEF WEBAPACHEHTTP}
2046+
{$IF Defined(WEBAPACHEHTTP)}
20482047
if FRequest.ClassType = TApacheRequest then
20492048
begin
20502049
Exit(hftApache);
20512050
end;
20522051
{$ENDIF}
2053-
{$IFDEF MSWINDOWS}
2052+
{$IF Defined(MSWINDOWS)}
20542053
if FRequest.ClassType = TISAPIRequest then
20552054
begin
20562055
Exit(hftISAPI);
@@ -2091,13 +2090,6 @@ constructor TMVCErrorResponseItem.Create(const AMessage: string);
20912090
FMessage := AMessage;
20922091
end;
20932092

2094-
{ TMVCIndyWebRequest }
2095-
2096-
// function TMVCIndyWebRequest.RawHeaders: TStrings;
2097-
// begin
2098-
// Result := TMVCHackHTTPAppRequest(FWebRequest).GetHeaders;
2099-
// end;
2100-
21012093
function TWebContext.GetLoggedUser: TUser;
21022094
begin
21032095
if not Assigned(FLoggedUser) then
@@ -2197,7 +2189,6 @@ procedure TWebContext.SessionStop(const ARaiseExceptionIfExpired: Boolean);
21972189
begin
21982190
raise EMVCSessionExpiredException.Create('Session not started');
21992191
end;
2200-
//SId := TMVCEngine.ExtractSessionIdFromWebRequest(FRequest.RawWebRequest);
22012192
GlobalSessionList.Remove(SId);
22022193
if SId <> '' then
22032194
begin
@@ -2416,7 +2407,7 @@ function TMVCEngine.ExecuteAction(const ASender: TObject; const ARequest: TWebRe
24162407
[(FConfigCache_MaxRequestSize div 1024)]);
24172408
end;
24182409

2419-
{$IFDEF BERLINORBETTER}
2410+
{$IF Defined(BERLINORBETTER)}
24202411
ARequest.ReadTotalContent;
24212412

24222413
// Double check for malicious content-length header

0 commit comments

Comments
 (0)