Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #19 - InvalidCastException when casting int to long and vice-versa #32

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

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.

None yet

1 participant