Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Jsonize int64 surprise
Jsonize int64 surprise [message #38862] Thu, 24 January 2013 19:51 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

It looks like jsonizing big int64 numbers leads to "string" representation instead of direct one.
I consider this bad kind of surprise as one's completely unable to send ANY big (int64) numbers to browser. I.e. you need to send some JSON containing javascript timestamp (which is really big int64 number) with int64 member. But you'll be surprised that this javascript code wont't work:
var d = new Date(receivedJson.t);

because t is not 1274574567221 but is a string '1274574567221'.

Looking into U++ core code reveals following:
		
//Core/JSON.cpp @ 238
if(var >= INT_MIN && var <= INT_MAX)
			io.Set(var);
		else
			io.Set(AsString(var));


I propose eliminating such a surprise party leaving int64 numbers as it is. Besides all known to me modern javascript implementations DO SUPPORT int64 integer numbers by default.

[Updated on: Thu, 24 January 2013 19:53]

Report message to a moderator

Re: Jsonize int64 surprise [message #38865 is a reply to message #38862] Thu, 24 January 2013 20:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I do not know. Quick internet search reveals that JSON format in principle cannot support int64. E.g.

http://json.codeplex.com/workitem/20832

Anyway, what we perhaps COULD do it to increase limits to accomodate 'precise integer' range of double (that is, if I remember well, 56-bits). That would be JSON compliant.

Mirek
Re: Jsonize int64 surprise [message #38867 is a reply to message #38865] Thu, 24 January 2013 20:21 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

I may be wrong. But my point is that JSON is used mostly in Web development. In our case this means:
Quote:

server[U++] <-> client[javascript]

And javascript natively supports integers up to 64-bit length (actually 53-bit, see below). So should we in U++.
This article
http://cdivilly.wordpress.com/2012/04/11/json-javascript-lar ge-64-bit-integers/
corrects that Javascript actually support integers up to 2^53. So if we really want to be close to standards here, we should check not INT_MAX, but 2^53 for stringification.

But I'd suggest eliminating ANY surprises at all. We have number - we represent as number. But one may disagree with it.

[Updated on: Thu, 24 January 2013 20:26]

Report message to a moderator

Re: Jsonize int64 surprise [message #38868 is a reply to message #38867] Thu, 24 January 2013 20:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Thu, 24 January 2013 14:21

I may be wrong. But my point is that JSON is used mostly in Web development. In our case this means:
Quote:

server[U++] <-> client[javascript]

And javascript natively supports integers up to 64-bit length (actually 53-bit, see below). So should we in U++.
This article
http://cdivilly.wordpress.com/2012/04/11/json-javascript-lar ge-64-bit-integers/
corrects that Javascript actually support integers up to 2^53. So if we really want to be close to standards here, we should check not INT_MAX, but 2^53 for stringification.



Well, but that actually is exactly what I propose (I just got 56 wrong, it is indeed 53).

Quote:


But I'd suggest eliminating ANY surprises at all. We have number - we represent as number. But one may disagree with it.


Well, there seems to be no 100% correct solution, but I think that lost precision would not be a good thing as well...

Mirek
Re: Jsonize int64 surprise [message #38869 is a reply to message #38868] Thu, 24 January 2013 20:43 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

mirek wrote on Thu, 24 January 2013 22:30

that actually is exactly what I propose (I just got 56 wrong, it is indeed 53).

Excellent. So here's change I propose:
//JSON.cpp @ 238
		{
			static const int64 JSON_INT_MIN = -9007199254740992LL;
			static const int64 JSON_INT_MAX =  9007199254740991LL;

			if(var >= JSON_INT_MIN && var <= JSON_INT_MAX)
				io.Set(var);
			else
				io.Set(AsString(var));
		}
Re: Jsonize int64 surprise [message #38870 is a reply to message #38869] Thu, 24 January 2013 21:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Commited.

Mirek
Re: Jsonize int64 surprise [message #38951 is a reply to message #38870] Tue, 29 January 2013 08:06 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

By the way same situation with int64 in XMLize class!

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Jsonize int64 surprise [message #38952 is a reply to message #38951] Tue, 29 January 2013 08:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Tue, 29 January 2013 02:06

By the way same situation with int64 in XMLize class!


That is strange, at the first glance it looks ok (mostly because in XML, you need to store it as string no matter what...)

Mirek
Re: Jsonize int64 surprise [message #38954 is a reply to message #38952] Tue, 29 January 2013 10:37 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Check pls Sql for int64 columns also.
(I've spent many many hours to discover problem, that int64 is String Value)


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Jsonize int64 surprise [message #38955 is a reply to message #38954] Tue, 29 January 2013 10:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Tue, 29 January 2013 04:37

Check pls Sql for int64 columns also.
(I've spent many many hours to discover problem, that int64 is String Value)


Sql depends on database used. Some might have issue...

Mirek
Re: Jsonize int64 surprise [message #38960 is a reply to message #38955] Tue, 29 January 2013 21:59 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I've test with MySQL.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Jsonize int64 surprise [message #38962 is a reply to message #38960] Wed, 30 January 2013 08:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Confirmed and filed into RM.

Mirek
Re: Jsonize int64 surprise [message #38963 is a reply to message #38962] Wed, 30 January 2013 09:01 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

And may you patch Sqlite3 schema plugin to do not convert int64 to int Type?

Sqlite normally eat int64 declaration, but if I write universal SqlExp expression - Sqlite3 schemaparser convert int64 to int. It's sad! Sad

uppsrc/plugin/sqlite3/Sqlite3Schema.h:
Now:
#define INT64(x)                   COLUMN("integer", int64, x, 0, 0)
#define INT64_ARRAY(x, items)      COLUMN_ARRAY("integer", int64, x, 0, 0, items)
#define INT64_(x)                  COLUMN_("integer", int64, x, 0, 0)
#define INT64_ARRAY_(x, items)     COLUMN_ARRAY_("integer", int64, x, 0, 0, items)


Need and tested:
#define INT64(x)                   COLUMN("bigint", int64, x, 0, 0)
#define INT64_ARRAY(x, items)      COLUMN_ARRAY("bigint", int64, x, 0, 0, items)
#define INT64_(x)                  COLUMN_("bigint", int64, x, 0, 0)
#define INT64_ARRAY_(x, items)     COLUMN_ARRAY_("bigint", int64, x, 0, 0, items)


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Wed, 30 January 2013 09:09]

Report message to a moderator

Previous Topic: Is FrameLess() working under Linux ?
Next Topic: Request: completion 64 bit support in Draw and Stream
Goto Forum:
  


Current Time: Thu Mar 28 10:14:25 CET 2024

Total time taken to generate the page: 0.01210 seconds