New helper method: ObjectToJSONObjectStr to easily convert an object to a json string

This commit is contained in:
Daniele Teti 2024-10-16 07:59:51 +02:00
parent 8727e3a6b1
commit 179a50dcda
2 changed files with 15 additions and 0 deletions

View File

@ -28,6 +28,7 @@ implementation
uses
WineCellarAppControllerU,
MVCFramework.Middleware.StaticFiles,
MVCFramework.Middleware.CORS,
System.IOUtils;
{$R *.dfm}
@ -40,6 +41,7 @@ begin
// Conf.Value[tmvcconfigkey.PathPrefix] := '/dmvc';
end);
MVCEngine.AddController(TWineCellarApp);
MVCEngine.AddMiddleware(TMVCCORSMiddleware.Create);
if not IsLibrary then
begin
MVCEngine.AddMiddleware(TMVCStaticFilesMiddleware.Create('/app', { StaticFilesPath }

View File

@ -673,6 +673,7 @@ function BuildContentType(const aContentMediaType: string; const aContentCharSet
function StrToJSONObject(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonObject;
function StrToJSONArray(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonArray;
function ObjectToJSONObject(const aObject: TObject): TJSONObject;
function ObjectToJSONObjectStr(const aObject: TObject): String;
function WrapAsList(const AObject: TObject; AOwnsObject: Boolean = False): IMVCList;
@ -1788,6 +1789,18 @@ begin
end;
end;
function ObjectToJSONObjectStr(const aObject: TObject): String;
var
lJSON: TJsonObject;
begin
lJSON := ObjectToJSONObject(aObject);;
try
Result := lJSON.ToJSON(True);
finally
lJSON.Free;
end;
end;
function StrToJSONObject(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonObject;
begin
Result := MVCFramework.Utils.StrToJSONObject(aString, ARaiseExceptionOnError);