You are not logged in.
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
....
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
In addition to the post above, fLastClass needs to be reset to nil after removal...
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