kgabis/parson

When parsing big integrals, json_object_get_number() returns incorrect results.

gtrevi opened this issue · 1 comments

Hi,

If I’m not missing other alternatives, the json_object_get_number() method is the only method for reading number values, but since the method returns a double, casting with big integral values is not guaranteed to work on all platforms.

For example, if a JSON document contains a "timestamp" property with an epoch value (i.e. time_t/int64_t/long long), the conversion returns an incorrect result, and casting won't work either:

{
"responseTimestamp": 1611842820791,
"httpCode": 200,
"statusCode": 0
}
...
double dTimestamp = json_object_get_number(rootObject, "responseTimestamp"); // returns 1611848455078 (incorrect)
time_t t = (time_t)json_object_get_number(rootObject, "responseTimestamp"); // returns 0x7fffffff (incorrect)
...

While reading the values of httpCode and statusCode return correct values, reading responseTimestamp, which was serialized from a time_t, doesn't.

Are there possible workarounds, besides implementing a method to specifically process big integrals (long long)?

Thanks!

Hi, this was already discussed in #134.