[fpc-pascal] JSON - RTTI streaming.

Lee Jenkins lee at datatrakpos.com
Tue May 17 16:53:02 CEST 2011

On 1/5/2011 6:12 PM, Michael Van Canneyt wrote:
> Hello,
> For those of you that need JSON support:
> I have committed support for streaming published properties (properties for
> which RTTI is generated) from objects to JSON and vice versa, in a unit fpjsonrtti.
> Not the full streaming as implemented in the classes system is supported:
> - No DefineProperties.
> - No methods.
> Although it should not be difficult to add support for this.
> In contrast, it can stream simple collections and stringlists (with ojects
> attached) in various ways.
> There are various events to influence the streaming process.
> This should be more than enough to stream objects to and from a web-browser.
> I have committed an example and a testsuite.
> All this is in packages/fcl-json.
> Despite the fact that the testsuite runs OK , I'd like to ask those for whom it
> might be useful to test the code and report any errors you find to me.
> Suggestions for improvements are also welcome.

Cool stuff, Michael.

One thought.  What do you think about a base abstract "TObjectStreamer" or 
similar object that provides methods that all such helpers could inherit from? 

TObejctStreamer = class(TObject)
   function    ToString: string; virtual; abstract;
   function    ToStream(AStream: TStream): integer; virtual; abstract;
   function    FromString(const AString: string): TObject; virtual; abstract;
   function    FromStream(AStream: TStream): TObject; virtual; abstract;

No sooner will you have started using a json object streamer in your project 
when the need for a xml or yaml format is required!  This could allow to swap 
out different implementations and promote decoupling.

BTW, do you ever sleep?

Warm Regards,


More information about the fpc-pascal mailing list