David Schwartz 426 Posted November 22, 2018 (edited) Does anybody happen to have an example of how to Serialize/Deserialize a TObjectDictionary with JSON? Most of the examples I've found are for several versions ago, and I've heard that the JSON classes keep improving. There seems to be two or three different approaches, none of which strike me as very straightforward. The class I'm using in this case contains two strings and a TObjectList of simple objects that contain two integers (similar to TPoints). Edited November 22, 2018 by David Schwartz Share this post Link to post
Andrea Magni 75 Posted November 23, 2018 Hi, I guess you mean TObjectDictionary<Key,Value> from Generics.Collections... Are you looking for a general solution or you can restrict Key or Value (or both) to some more specific type? Share this post Link to post
Alexander Elagin 143 Posted November 23, 2018 Have you tried this library: https://blog.grijjy.com/2017/01/30/efficient-and-easy-to-use-json-and-bson-library/ Just a week ago I had to implement a JSON file reader - never used JSON before - and decided to try this library. It was surprisingly easy to use. Share this post Link to post
Davide Visconti 5 Posted November 24, 2018 15 hours ago, Alexander Elagin said: Have you tried this library: https://blog.grijjy.com/2017/01/30/efficient-and-easy-to-use-json-and-bson-library/ Just a week ago I had to implement a JSON file reader - never used JSON before - and decided to try this library. It was surprisingly easy to use. Wow! Very powerful. I'll try it ASAP because I'm searching a serialize/deserialize library. Thanks for sharing. Share this post Link to post
ertank 27 Posted November 24, 2018 10 hours ago, Davide Visconti said: I'll try it ASAP because I'm searching a serialize/deserialize library. You might want to check mORMot JSON routines. They are record based. Works out pretty good for me. Fast start thread: https://synopse.info/forum/viewtopic.php?id=1132 Share this post Link to post
David Schwartz 426 Posted November 25, 2018 (edited) On 11/23/2018 at 9:02 AM, Andrea Magni said: Hi, I guess you mean TObjectDictionary<Key,Value> from Generics.Collections... yes, I've got one of these with 7500 elements in it, It takes a couple of minutes to build, and once it's loaded-up, it never changes. So I want to save it to disk or a BLOB in a DB and reload it later instead of having to rebuild it each time. All I need is .SaveToStream and .LoadFromStream. It doesn't need to be human readable; faster is better. Edited November 25, 2018 by David Schwartz Share this post Link to post
David Schwartz 426 Posted December 6, 2018 Just following-up ... I ended up doing something fairly simple to de/serialize a few of my classes. Nothing special, and it turned out to be quite easy. But I've been looking over the Grijjy code and it looks like the Griggy.ProtocolBuffers unit is perfect for what I need. I may go back and replace what I'd done. I could have also used BSON because there's no need to be able to read the serialized data. Thanks for the suggestions. 🙂 Share this post Link to post
Clément 148 Posted December 6, 2018 (edited) Hi. I also ended up writing my own JSON serializer/deserializer based on delphi TJsonObject. (Using another JSON class created incompatibilities with RTL). It works on generics (TDictionary<>, TObjectDictionary<>, Tlist<>, etc), Tdataset, TStringList, enum and nested classes. Quite fast. I needed a special TDataset handling (speed wise) that none of the library I tried solved. Anyway, sometimes it's worth reinventing the wheel! Edited December 6, 2018 by Clément Share this post Link to post