Skip to content

Conversation

prestonj
Copy link

Modified handling of int and long data types. Now it is possible to cast ints to longs and vice-versa (assuming the data is within range). You can also do equality comparisons between the two. I've updated the test routine to no longer fail when comparing 10 and 10L.

Rationale: When json data is read in, litJson decides on what data type to assign to the data. For integer numerics, litjson dynamically chooses between int and long data types based on the size of the number. If it fits in an int, the data type becomes an int. However this complicates the data handling routines for the user as they cannot predetermine what type to use. Code such as the following:

long myvalue = (long) JsonData["some_number"];

would fail with an InvalidCastException when some_number was in the range of an int.

It might be worthwhile in the future to handle integer numerics using a single data type (e.g. long).

…ast ints to longs and vice-versa (assuming the data is within range). You can also do equality comparisons between the two. I've updated the test routine to no longer fail when comparing 10 and 10L.

Rationale: When json data is read in, litJson decides on what data type to assign to the data. For integer numerics, litjson dynamically chooses between int and long data types based on the size of the number. If it fits in an int, the data type becomes an int. However this complicates the data handling routines for the user as they cannot predetermine what type to use. Code such as the following:

long myvalue = (long) JsonData["some_number"];

would fail with an InvalidCastException when some_number was in the range of an int.

It might be worthwhile in the future to handle integer numerics using a single data type (e.g. long).
@devlead devlead changed the base branch from master to develop December 22, 2017 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant