unit untJSON;

interface

uses
  Classes, SysUtils, System.JSON.Serializers, System.JSON.Types;

type
  TJSON = class
  public
    class function ObjectToJson<T>(AObj: T): string;
    class function JsonToObject<T>(AJson: string): T;
  end;

implementation


class function TJSON.JsonToObject<T>(AJson: string): T;
var
  serializer: TJsonSerializer;
begin
  serializer := TJsonSerializer.Create;
  try
    Result := serializer.Deserialize<T>(AJson);
  finally
    serializer.Free;
  end;
end;

{ TJSON<T> }

class function TJSON.ObjectToJson<T>(AObj: T): string;
var
  serializer: TJsonSerializer;
begin
  Result := '';
  serializer := TJsonSerializer.Create;
  serializer.Formatting := TJsonFormatting.Indented;
  try
    Result := serializer.Serialize<T>(AObj);
  finally
    serializer.Free;
  end;
end;

end.
