Discussion:
TJSONDeStreamer can't handle such date format 'yyyy-MM-dd"T"hh:nn:ss"Z"'
(too old to reply)
Stéphane Wierzbicki
2016-07-18 13:20:32 UTC
Permalink
Raw Message
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 ?
Michael Van Canneyt
2016-07-19 07:54:45 UTC
Permalink
Raw Message
Post by 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"'
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.
Dimitrios Chr. Ioannidis
2016-07-19 08:43:07 UTC
Permalink
Raw Message
<snip>
Post by Michael Van Canneyt
Post by Stéphane Wierzbicki
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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-
Michael Van Canneyt
2016-07-19 08:47:43 UTC
Permalink
Raw Message
Post by Dimitrios Chr. Ioannidis
<snip>
Post by Michael Van Canneyt
Post by Stéphane Wierzbicki
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
Number of run tests: 322
Number of errors: 0
Number of failures: 2
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
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.
Sven Barth
2016-07-19 09:08:24 UTC
Permalink
Raw Message
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
<snip>
Post by Michael Van Canneyt
Post by Stéphane Wierzbicki
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
Number of run tests: 322
Number of errors: 0
Number of failures: 2
Message: TTestJSONStreamer.TestWriteFloat4: "Correct
value" expected: <4,56> but was: <5>
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
Exception class: EAssertionFailedError
Exception message: "Correct value" expected: <4,56> but was: <5>
at $00434358 TTESTJSONSTREAMER__ASSERTPROP, line 761 of
testjsonrtti.pp
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
Message: TTestJSONDeStreamer.TestFloat4: "Correct extended
value" expected: <5,67> but was: <6>
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
Exception class: EAssertionFailedError
Exception message: "Correct extended value" expected: <5,67> but
was: <6>
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of
testjsonrtti.pp
Post by Michael Van Canneyt
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
Michael Van Canneyt
2016-07-19 09:13:01 UTC
Permalink
Raw Message
Post by Dimitrios Chr. Ioannidis
value" expected: <4,56> but was: <5>
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
Exception class: EAssertionFailedError
Exception message: "Correct value" expected: <4,56> but was: <5>
at $00434358 TTESTJSONSTREAMER__ASSERTPROP, line 761 of
testjsonrtti.pp
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
Message: TTestJSONDeStreamer.TestFloat4: "Correct extended
value" expected: <5,67> but was: <6>
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
Exception class: EAssertionFailedError
Exception message: "Correct extended value" expected: <5,67> but
was: <6>
Post by Michael Van Canneyt
Post by Dimitrios Chr. Ioannidis
at $0043241F TTESTJSONDESTREAMER__TESTFLOAT4, line 374 of
testjsonrtti.pp
Post by Michael Van Canneyt
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.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Luiz Americo Pereira Camara
2016-07-19 09:46:49 UTC
Permalink
Raw Message
Post by Dimitrios Chr. Ioannidis
Exception class: EAssertionFailedError
Post by Dimitrios Chr. Ioannidis
<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}

Luiz
Michael Van Canneyt
2016-07-19 09:55:36 UTC
Permalink
Raw Message
Post by Luiz Americo Pereira Camara
Post by Dimitrios Chr. Ioannidis
Exception class: EAssertionFailedError
Post by Dimitrios Chr. Ioannidis
<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)
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.
"
{$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.

Loading...