diff --git a/inst/include/jsonify/from_json/from_json.hpp b/inst/include/jsonify/from_json/from_json.hpp index d02b181..a49b04a 100644 --- a/inst/include/jsonify/from_json/from_json.hpp +++ b/inst/include/jsonify/from_json/from_json.hpp @@ -121,10 +121,15 @@ namespace from_json { } // numeric case rapidjson::kNumberType: { - if( json.IsDouble() ) { - return Rcpp::wrap< double >( json.GetDouble() ); - } else { + // if( json.IsDouble() || json.IsUint64() || json.IsInt64() ) { + // return Rcpp::wrap< double >( json.GetDouble() ); + // } else { + // return Rcpp::wrap< int >( json.GetInt() ); + // } + if( json.IsInt() ) { return Rcpp::wrap< int >( json.GetInt() ); + } else { + return Rcpp::wrap< double >( json.GetDouble() ); } } case rapidjson::kObjectType: { diff --git a/tests/testthat/test-from_json.R b/tests/testthat/test-from_json.R index bab9065..e648dc7 100644 --- a/tests/testthat/test-from_json.R +++ b/tests/testthat/test-from_json.R @@ -17,6 +17,11 @@ test_that("scalar values handled properly", { expect_equal(from_json("true"), TRUE) }) +test_that("Int64 treated as double", { + json_str <- '{"value" : 5500000000}' + expect_equal(from_json(json_obj)$value, 5.5e+09) +}) + test_that("vector / array values handled properly", { target <- list(a = list(1L, 2L, 3L, NA), b = list(1L, "cats", 3L, NA))