Sign in Join

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

Mailing lists / fpc-pascal / 2015-09

JSONRTTI load and save TDateTime issues

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

I'm using the JSONRTTI unit to successfully save an object to a .json file. But when loading that file back using TJSONDeStreamer I get a conversion error due to the Date/Time format.

Here is the code to handle the TDateTime fields of my object - I store them as ISO8601 date/time format.

  js := TJSONStreamer.Create(nil);
  try
    js.Options := [jsoDateTimeAsString];
    js.DateTimeFormat := 'yyyymmdd"T"hhnnss';
    j := js.ObjectToJSON(ASettings);

The problem is, the TJSONDeStreamer doesn't have the equivalent Options property or DateTimeFormat property that TJSONStreamer has, so how is it supposed to know how to handle Date/Time fields? No wonder it gives a Conversion Error.

If I comment out my js.DateTimeFormat line above, then saving and loading works. But I don't want the default DateTime-to-String result.

Any ideas? I'm using FPC 2.6.4.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
The problem is, the TJSONDeStreamer doesn't have the equivalent Options property or DateTimeFormat property that TJSONStreamer has, so how is it supposed to know how to handle Date/Time fields? No wonder it gives a Conversion Error.

I had a quick look at FPC 3.0 rc, and it also doesn't have the Options or DateTimeFormat properties for TJSONDeStreamer. So this issue would happen there too.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: I'm using the JSONRTTI unit to successfully save an object to a .json file. But when…
Graeme Geldenhuys wrote 25 lines
Hi, I'm using the JSONRTTI unit to successfully save an object to a .json file. But when loading that file back using TJSONDeStreamer I get a conversion error due to the Date/Time format. Here is the code to handle the TDateTime fields of my object - I store them as ISO8601 date/time format. js := TJSONStreamer.Create(nil); try js.Options := [jsoDateTimeAsString]; js.DateTimeFormat := 'yyyymmdd"T"hhnnss'; j := js.ObjectToJSON(ASettings); The problem is, the TJSONDeStreamer doesn't have the equivalent Options property or DateTimeFormat property that TJSONStreamer has, so how is it supposed to know how to handle Date/Time fields? No wonder it gives a Conversion Error. If I comment out my js.DateTimeFormat line above, then saving and loading works. But I don't want the default DateTime-to-String result. Any ideas? I'm using FPC 2.6.4.

That's a bug (missing jsoDateTimeAsString in destreamer), please report it in the bugtracker.

Michael.

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 5 lines
On 2015-09-24 13:06, Michael Van Canneyt wrote: > That's a bug (missing jsoDateTimeAsString in destreamer), > please report it in the bugtracker. OK, but against which version of FPC?

Trunk.

Michael.

Reply by email