JSON persistence

Trying to adopt the blog article to serialize a generic list in a Electron app

The serialization to JSON is working, but the deserialization from JSON not, getting an empty list.

From what base class should I derive my list? Should

 TItem = class(TPersistent)
    FName: string;
    FDescription: string;
    constructor Create; overload;
    constructor Create(Name : string; Description : string); overload;
    property Name: string read FName write FName;
    property Description: string read FDescription write FDescription;

TItemList = class(TList<TItem>)
    function GetItem(Index : Integer) : TItem ;
    procedure SetItem(Index : Integer; const Item : TItem );
    function Add(const Item : TItem ) : Integer;
    property Item[Index: Integer]: TItem read GetItem write SetItem;


Seems, that when deserializing, the list item class TItem can not be created.


You can use the approach from the following post code snippet:

Thank you for pointing me the right direction to go. I already understood that I have to implemend the ITMSFNCBaseListIO, ITMSFNCBasePersistenceIO interfaces into my list class, but could not figure out how to implement the IInterface correctly. The pas2js compiler did not accept the stdcall declarations, but its running without.

Thank you

The sample and code snippet is not TMS WEB Core based. We'll look into a more generic example that works on all frameworks.

In chapter 4.13 Holger Flick describes in his book how to work with JSON in WEB Core, but I could not figure out how that works with generic lists.

Support for generics has been added after the book has been written. An addendum might be helpful here, so we'll look into it.