#1 2017-12-22 09:25:20

ComingNine
Member
Registered: 2010-07-29
Posts: 294

Could you add UnRegisterClassForJSON methods into mORMot.pas ?

When utilizing JSON serialization, one would try and test different versions of a specific class (isolated in different units). Under such circumstances, UnRegisterClassForJSON methods could be useful big_smile

....

    procedure RemoveOnce(aItemClass: TClass);

....

    class procedure UnRegisterClassForJSON(aItemClass: TClass); overload;
    class procedure UnRegisterClassForJSON(const aItemClass: array of TClass); overload;

....

procedure TJSONSerializerRegisteredClass.RemoveOnce(aItemClass: TClass);
begin
  fSafe.Lock;
  try
    if PtrUIntScanExists(pointer(List),Count,PtrUInt(aItemClass)) then
      Remove(aItemClass);
  finally
    fSafe.UnLock;
  end;
end;

....

class procedure TJSONSerializer.UnRegisterClassForJSON(aItemClass: TClass);
begin
  if JSONSerializerRegisteredClass=nil then
    GarbageCollectorFreeAndNil(JSONSerializerRegisteredClass,
      TJSONSerializerRegisteredClass.Create);
  JSONSerializerRegisteredClass.RemoveOnce(aItemClass);
end;

class procedure TJSONSerializer.UnRegisterClassForJSON(const aItemClass: array of TClass);
var i: integer;
begin
  for i := 0 to high(aItemClass) do
    UnRegisterClassForJSON(aItemClass[i]);
end;

Offline

#2 2017-12-22 16:58:57

ComingNine
Member
Registered: 2010-07-29
Posts: 294

Re: Could you add UnRegisterClassForJSON methods into mORMot.pas ?

In addition to the post above, fLastClass needs to be reset to nil after removal... smile

procedure TJSONSerializerRegisteredClass.RemoveOnce(aItemClass: TClass);
begin
  fSafe.Lock;
  try
    if PtrUIntScanExists(pointer(List),Count,PtrUInt(aItemClass)) then begin
      Remove(aItemClass);
      if fLastClass = aItemClass then
        fLastClass := nil;
    end;  
  finally
    fSafe.UnLock;
  end;
end;

Offline

Board footer

Powered by FluxBB