#1 2015-06-20 21:38:09

BBackSoon
Member
Registered: 2014-11-15
Posts: 41

TDictionary/TObjectDictionary JSON (de)serialization

I'll try to be brief, and on the spot.
So, this is what I have:

var
  fVFSystems: TObjectDictionary<string, TVFSContainer>;

I also call these 2 methods, to make sure mORMot knows the necessary classes:

TJSONSerializer.RegisterClassForJSON(TVFSContainer);
TJSONSerializer.RegisterClassForJSON(TObjectDictionary<string, TVFSContainer>);

Then I call:

  MyJSONString := ObjectToJSON(fVFSystems, [woHumanReadable]);

And yet, after the above call, MyJSONString still contains an empty JSON { }.
What am I doing wrong?

Offline

#2 2015-06-20 22:18:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: TDictionary/TObjectDictionary JSON (de)serialization

Such kind of generic class are not directly supported.

They are not value objects, and would need a dedicated code for each kind.
For instance, each kind of dictionary would need to be declared.

The only solution is to register your custom serialization for the specific type.
See http://synopse.info/files/html/api-1.18 … SERIALIZER
and http://synopse.info/files/html/Synopse% … ml#TITL_52

Offline

Board footer

Powered by FluxBB