Sign in Join

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

Mailing lists / fpc-devel / 2016-07

TJSONDeStreamer can't handle such date format 'yyyy-MM-dd"T"hh:nn:ss"Z"'

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Stéphane Wierzbicki

Hello,

I'm working with the TJSONStreamer and TJSONDeStreamer class. I need to exchange JSON object with a REST server. Date needs to be formatted this way : 'yyyy-MM-dd"T"hh:nn:ss"Z"'
Here is what I've done :

Streamer.Options := Streamer.Options + [jsoDateTimeAsString ,
jsoUseFormatString];
Streamer.DateTimeFormat := 'yyyy-MM-dd"T"hh:nn:ss"Z"';  //ISO8601
JSONString := Streamer.ObjectToJSONString(MyObject);
....
DeStreamer.JSONToObject(JSONString , MyObject);  <= Exception

I'm getting an exception when converting my string to the object again. TJSONDeStreamer failed to convert this format back to 'yyyy-MM-dd"T"hh:nn:ss"Z".

I have modified TJSONStreamer and TJSONDeStreamer class to handle ISO8601 dates by adding a new jsoDateTimeAsISO8601 option. Where can I send these modifications ?

Reply by email

Michael Van Canneyt
to Stéphane Wierzbicki
Stéphane Wierzbicki wrote 21 lines
Hello, I'm working with the TJSONStreamer and TJSONDeStreamer class. I need to exchange JSON object with a REST server. Date needs to be formatted this way : 'yyyy-MM-dd"T"hh:nn:ss"Z"' Here is what I've done : Streamer.Options := Streamer.Options + [jsoDateTimeAsString , jsoUseFormatString]; Streamer.DateTimeFormat := 'yyyy-MM-dd"T"hh:nn:ss"Z"'; //ISO8601 JSONString := Streamer.ObjectToJSONString(MyObject); .... DeStreamer.JSONToObject(JSONString , MyObject); <= Exception I'm getting an exception when converting my string to the object again. TJSONDeStreamer failed to convert this format back to 'yyyy-MM-dd"T"hh:nn:ss"Z". I have modified TJSONStreamer and TJSONDeStreamer class to handle ISO8601 dates by adding a new jsoDateTimeAsISO8601 option. Where can I send these modifications ?

What version of FPC did you use ?

The latest version of TJSONStreamer and TJSONDeStreameruse this format already, check the jsoLegacyDateTime option.

Michael.

Reply by email

Dimitrios Chr. Ioannidis
to Michael Van Canneyt
Michael Van Canneyt wrote
On Mon, 18 Jul 2016, Stéphane Wierzbicki wrote:

<snip>

Show quoted text 9 lines
> I have modified TJSONStreamer and TJSONDeStreamer class to handle > ISO8601 > dates by adding a new jsoDateTimeAsISO8601 option. > Where can I send these modifications ? What version of FPC did you use ? The latest version of TJSONStreamer and TJSONDeStreameruse this format already, check the jsoLegacyDateTime option.

With fixes_3.0 branch rev. 34112 ( also in today's trunk ), the json testsuite reports two failures :

Number of run tests: 322
Number of errors: 0
Number of failures: 2

List of failures:
Failure:
Message: TTestJSONStreamer.TestWriteFloat4: "Correct value" expected: <4,56> but was: <5>
Exception class: EAssertionFailedError
Exception message: "Correct value" expected: <4,56> but was: <5> at $00434358 TTESTJSONSTREAMER__ASSERTPROP, line 761 of testjsonrtti.pp
Failure:
Message: TTestJSONDeStreamer.TestFloat4: "Correct extended value" expected: <5,67> but was: <6>
Exception class: EAssertionFailedError
Exception message: "Correct extended value" expected: <5,67> but was: <6>
at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of testjsonrtti.pp

regards,

Dimitrios Chr. Ioannidis

Reply by email

Michael Van Canneyt
to Dimitrios Chr. Ioannidis
Dimitrios Chr. Ioannidis wrote 41 lines
On 19/7/2016 10:54 πμ, Michael Van Canneyt wrote: > > > On Mon, 18 Jul 2016, Stéphane Wierzbicki wrote: > <snip> >> I have modified TJSONStreamer and TJSONDeStreamer class to handle >> ISO8601 >> dates by adding a new jsoDateTimeAsISO8601 option. >> Where can I send these modifications ? > > What version of FPC did you use ? > > The latest version of TJSONStreamer and TJSONDeStreameruse this format > already, check the jsoLegacyDateTime option. With fixes_3.0 branch rev. 34112 ( also in today's trunk ), the json testsuite reports two failures : Number of run tests: 322 Number of errors: 0 Number of failures: 2 List of failures: Failure: Message: TTestJSONStreamer.TestWriteFloat4: "Correct value" expected: <4,56> but was: <5> Exception class: EAssertionFailedError Exception message: "Correct value" expected: <4,56> but was: <5> at $00434358 TTESTJSONSTREAMER__ASSERTPROP, line 761 of testjsonrtti.pp Failure: Message: TTestJSONDeStreamer.TestFloat4: "Correct extended value" expected: <5,67> but was: <6> Exception class: EAssertionFailedError Exception message: "Correct extended value" expected: <5,67> but was: <6> at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of testjsonrtti.pp

I am aware of this.

However, this is only on i386, on 64-bit the code runs fine. I have no idea why, the code should be CPU agnostic.

I have not yet had the opportunity to debug it on a i386 machine.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
"Michael Van Canneyt" wrote 15 lines
On Tue, 19 Jul 2016, Dimitrios Chr. Ioannidis wrote: > On 19/7/2016 10:54 πμ, Michael Van Canneyt wrote: >> >> >> >> On Mon, 18 Jul 2016, Stéphane Wierzbicki wrote: >> > > <snip> > >>> I have modified TJSONStreamer and TJSONDeStreamer class to handle

ISO8601

Show quoted text 11 lines
>>> dates by adding a new jsoDateTimeAsISO8601 option. >>> Where can I send these modifications ? >> >> >> What version of FPC did you use ? >> >> The latest version of TJSONStreamer and TJSONDeStreameruse this format >> already, check the jsoLegacyDateTime option. > > > With fixes_3.0 branch rev. 34112 ( also in today's trunk ), the json

testsuite reports two failures :

Show quoted text 8 lines
> > Number of run tests: 322 > Number of errors: 0 > Number of failures: 2 > > List of failures: > Failure: > Message: TTestJSONStreamer.TestWriteFloat4: "Correct

value" expected: <4,56> but was: <5>

> Exception class: EAssertionFailedError > Exception message: "Correct value" expected: <4,56> but was: <5> > at $00434358 TTESTJSONSTREAMER__ASSERTPROP, line 761 of

testjsonrtti.pp

> Failure: > Message: TTestJSONDeStreamer.TestFloat4: "Correct extended

value" expected: <5,67> but was: <6>

> Exception class: EAssertionFailedError > Exception message: "Correct extended value" expected: <5,67> but

was: <6>

> at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of

testjsonrtti.pp

Show quoted text 8 lines
I am aware of this. However, this is only on i386, on 64-bit the code runs fine. I have no idea why, the code should be CPU agnostic. I have not yet had the opportunity to debug it on a i386 machine.

Judging by the errors that is probably due to the compiler using Extended for some evaluations. You'd need to force them to Double or Single to avoid that.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 25 lines
value" expected: <4,56> but was: <5> >> Exception class: EAssertionFailedError >> Exception message: "Correct value" expected: <4,56> but was: <5> >> at $00434358 TTESTJSONSTREAMER__ASSERTPROP, line 761 of testjsonrtti.pp >> Failure: >> Message: TTestJSONDeStreamer.TestFloat4: "Correct extended value" expected: <5,67> but was: <6> >> Exception class: EAssertionFailedError >> Exception message: "Correct extended value" expected: <5,67> but was: <6> >> at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of testjsonrtti.pp > > > I am aware of this. > > However, this is only on i386, on 64-bit the code runs fine. > I have no idea why, the code should be CPU agnostic. > > I have not yet had the opportunity to debug it on a i386 machine. Judging by the errors that is probably due to the compiler using Extended for some evaluations. You'd need to force them to Double or Single to avoid that.

Huh ? How can using a higher precision type lead to _less_ precision ???

Michael.

Reply by email

Luiz Americo Pereira Camara
to Michael Van Canneyt: I am aware of this. However, this is only on i386, on 64-bit the code runs fine. I have…

2016-07-19 5:47 GMT-03:00 Michael Van Canneyt :

Show quoted text 18 lines
On Tue, 19 Jul 2016, Dimitrios Chr. Ioannidis wrote: Exception class: EAssertionFailedError > Exception message: "Correct extended value" expected: <5,67> but was: > <6> > at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of > testjsonrtti.pp > I am aware of this. However, this is only on i386, on 64-bit the code runs fine. I have no idea why, the code should be CPU agnostic. I have not yet had the opportunity to debug it on a i386 machine.

I just looked at it in this weekend.

After doing some tests and reading the docs i realized that is not a bug in fpjsonrtti, nor a write directly 4.56 to the property (of comp type). Reading it directly gives a rounded value (5)

Than i read the docs:
http://www.freepascal.org/docs-html/ref/refsu6.html "The Comp type is, in effect, a 64-bit integer and is not available on all target platforms. To get more information on the supported types for each platform, refer to the Programmer’s Guide. "

http://www.freepascal.org/docs-html/prog/progsu160.html#x204-2130008.2.5 "Comp

For Intel 80x86 processors, the comp type contains a 63-bit integral value, and a sign bit (in the MSB position). The comp type uses 8 bytes of storage space.

On other processors, the comp type is not supported. "

It works in 64bit cpu because is testing other code:

{$ifdef CPUX86_64}
    AssertProp('ExtendedProp',TJSONFloat(5));
  {$else}
    AssertProp('ExtendedProp',4.56);
  {$endif}

Luiz

Reply by email

Michael Van Canneyt
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote 52 lines
2016-07-19 5:47 GMT-03:00 Michael Van Canneyt : > > > On Tue, 19 Jul 2016, Dimitrios Chr. Ioannidis wrote: > > Exception class: EAssertionFailedError >> Exception message: "Correct extended value" expected: <5,67> but was: >> <6> >> at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of >> testjsonrtti.pp >> > > I am aware of this. > > However, this is only on i386, on 64-bit the code runs fine. > I have no idea why, the code should be CPU agnostic. > > I have not yet had the opportunity to debug it on a i386 machine. > I just looked at it in this weekend. After doing some tests and reading the docs i realized that is not a bug in fpjsonrtti, nor a bug at all. First write directly 4.56 to the property (of comp type). Reading it directly gives a rounded value (5) Than i read the docs: http://www.freepascal.org/docs-html/ref/refsu6.html "The Comp type is, in effect, a 64-bit integer and is not available on all target platforms. To get more information on the supported types for each platform, refer to the Programmer’s Guide. " http://www.freepascal.org/docs-html/prog/progsu160.html#x204-2130008.2.5 "Comp For Intel 80x86 processors, the comp type contains a 63-bit integral value, and a sign bit (in the MSB position). The comp type uses 8 bytes of storage space. On other processors, the comp type is not supported. " It works in 64bit cpu because is testing other code: {$ifdef CPUX86_64} AssertProp('ExtendedProp',TJSONFloat(5)); {$else} AssertProp('ExtendedProp',4.56); {$endif}

Haha... I was thrown off by the ExtendedProp in the error reports. That should be CompProp obviously. I will adapt the test code accordingly.

Many many thanks for spotting this !!

Michael.

Reply by email