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

Commits on Nov 19, 2014

  1. Modified handling of int and long data types. Now it is possible to c…

    …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).
    prestonj committed Nov 19, 2014
    Configuration menu
    Copy the full SHA
    bec3edc View commit details
    Browse the repository at this point in the history