Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-01

JSON - RTTI streaming.

13 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

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.

Michael.

Reply by email

Brian Winfrey
to Michael Van Canneyt
Michael Van Canneyt wrote 30 lines
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. Michael. _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Nice, this was on my to do list.

Reply by email

Burkhard Carstens
to Michael Van Canneyt: For those of you that need JSON support: I have committed support for streaming published…
Michael Van Canneyt wrote 26 lines
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.

This is great!
A quick first test (streaming/destreaming a TPanel with childs) fails with: Unsuported JSON type for object property: "jtNull" This is line 296 in fpjsonrtti. Maybe jtNull should be interpreted as nil here..

regards
Burkhard

Reply by email

Unknown author
to Burkhard Carstens
Burkhard Carstens wrote 33 lines
Am Donnerstag, 6. Januar 2011 00:12 schrieb Michael Van Canneyt: > 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. This is great! A quick first test (streaming/destreaming a TPanel with childs) fails with: Unsuported JSON type for object property: "jtNull" This is line 296 in fpjsonrtti. Maybe jtNull should be interpreted as nil here..

It depends; jtNull can appear almost anywhere.
I guess that for pointer or class values, we can interpret it as Nil. I'll have a .

Reply by email

Lee Jenkins
to Michael Van Canneyt: For those of you that need JSON support: I have committed support for streaming published…
Michael Van Canneyt wrote 24 lines
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? Like:

TObejctStreamer = class(TObject)
Public
   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;
end;

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, Lee

Reply by email

Unknown author
to Lee Jenkins
Lee Jenkins wrote 42 lines
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? Like: TObejctStreamer = class(TObject) Public 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; end;

We have this in part, the abstract object streamers in the classes unit. I thought about implementing it like that, but then there is a problem: defineproperties is hard to do, because it expects a seekable stream, and that's just not possible with JSON.

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.

This could be implemented, yes. But I don't have the immediate need, so don't expect me to jump on this. I'm open for patches, though :-)

BTW, do you ever sleep?

Like a baby, once I scratched some of the FPC itches I have ;-)

Michael.

Reply by email

Stephane Carre
to Michael Van Canneyt: For those of you that need JSON support: I have committed support for streaming published…

Hello Michael,
In the current stable release (fpc 2.4.4) the unit tests for fpjsonrtti fail to compile because unit testcomps is missing. I believe this is the unit with the test classes used for the destreamer tests.
Where can I find this unit ?
Thanks for this !
Regards,
Stephane Carre

Michael Van Canneyt wrote 30 lines
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. Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Unknown author
to Stephane Carre
Stephane Carre wrote 6 lines
Hello Michael, In the current stable release (fpc 2.4.4) the unit tests for fpjsonrtti fail to compile because unit testcomps is missing. I believe this is the unit with the test classes used for the destreamer tests. Where can I find this unit ?

I probably forgot to commit it. I will send it to you tonight.

Michael.

Show quoted text 40 lines
Thanks for this ! Regards, Stephane Carre On 06/01/2011 00:12, 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. > > Michael. > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Stephane Carre
to Unknown author

Hello Michael,
I have not received any e-mail with the testcomps unit. Can you please make sure you send it to me ?
Thanks for your time !
Regards,
Stephane Carre

Show quoted text 14 lines
On Wed, 16 Nov 2011, Stephane Carre wrote: > Hello Michael, > In the current stable release (fpc 2.4.4) the unit tests for > fpjsonrtti fail to compile because unit testcomps is missing. > I believe this is the unit with the test classes used for the > destreamer tests. > Where can I find this unit ? I probably forgot to commit it. I will send it to you tonight. Michael.

Reply by email

Michael Van Canneyt
to Stephane Carre

It is attached.

It is committed, but probably not where you expected it :-)

Michael.

Stephane Carre wrote 27 lines
Hello Michael, I have not received any e-mail with the testcomps unit. Can you please make sure you send it to me ? Thanks for your time ! Regards, Stephane Carre On 17/11/2011 09:16, wrote: > > > On Wed, 16 Nov 2011, Stephane Carre wrote: > >> Hello Michael, >> In the current stable release (fpc 2.4.4) the unit tests for fpjsonrtti >> fail to compile because unit testcomps is missing. >> I believe this is the unit with the test classes used for the destreamer >> tests. >> Where can I find this unit ? > > I probably forgot to commit it. I will send it to you tonight. > > Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Stephane Carre
to Michael Van Canneyt

Thank you Michael.
I checked before in the fpc source 2.4.4 download available from sourceforge, but could not find testcomps anywhere. The version you attached does not contain TVariantComponent. Is that a newer, or older version than the one that should match fpc 2.4.4 ? Otherwise I guess I can adapt the missing pieces.
Best regards,
Stephane

Michael Van Canneyt wrote 41 lines
It is attached. It is committed, but probably not where you expected it :-) Michael. On Fri, 18 Nov 2011, Stephane Carre wrote: > Hello Michael, > I have not received any e-mail with the testcomps unit. > Can you please make sure you send it to me ? > Thanks for your time ! > Regards, > Stephane Carre > > On 17/11/2011 09:16, wrote: >> >> >> On Wed, 16 Nov 2011, Stephane Carre wrote: >> >>> Hello Michael, >>> In the current stable release (fpc 2.4.4) the unit tests for >>> fpjsonrtti fail to compile because unit testcomps is missing. >>> I believe this is the unit with the test classes used for the >>> destreamer tests. >>> Where can I find this unit ? >> >> I probably forgot to commit it. I will send it to you tonight. >> >> Michael. > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Stephane Carre
to Stephane Carre

Hello Michael,
Finally, I also found the original testcomps.pp file in the sources (and at the sime time I discovered a limitation of the Windows 7 file search tool, which was why I did not find the file before). As indicated below, the version that comes with the sources is not complete. I modified testcomps.pp so that the tests fully compile with the stable fpc 2.4.4 version.
It is attached here, I hope it helps.
Thank you for this json library !
Best regards,
Stephane

Stephane Carre wrote 18 lines
Thank you Michael. I checked before in the fpc source 2.4.4 download available from sourceforge, but could not find testcomps anywhere. The version you attached does not contain TVariantComponent. Is that a newer, or older version than the one that should match fpc 2.4.4 ? Otherwise I guess I can adapt the missing pieces. Best regards, Stephane On 18/11/2011 13:17, Michael Van Canneyt wrote: > > It is attached. > > It is committed, but probably not where you expected it :-) > > Michael. > >

Reply by email

Sven Barth
to Stephane Carre
Stephane Carre wrote
Finally, I also found the original testcomps.pp file in the sources (and at the sime time I discovered a limitation of the Windows 7 file search tool, which was why I did not find the file before).

That's a reason to use the file search of some editor (e.g. Lazarus or Notepad++) for something like this. ^^

Regards,
Sven

Reply by email