Open jboelterintc opened 7 months ago
I am having the same issue and apologies if I am not understanding this correctly as I am new to C++ and have only just started using this library, but it looks like the integer value is not being considered a basic_json and so is calling the explicit cast from_json. At least the comment above the function leads me to believe this.
// overload for arithmetic types, not chosen for basic_json template arguments
// (BooleanType, etc..); note: Is it really necessary to provide explicit
// overloads for boolean_t etc. in case of a custom BooleanType which is not
// an arithmetic type?
hi i am working on this.Will get something by this weekend.
Are you still working on this? I'm planning to look into it.
If I'm planning on contributing, is there any guidelines or styles that I need to follow while writing the code? If yes, where can I read about it? Thanks.
@amirghaz Do you need further assistance?
@nlohmann I'm a beginner with this library, so any insight that you have is highly appreciated.
Description
Converting from
"value": true
or"value": false
behaves unexpectedly and differently for certain integer types.I was expecting all conversions from a boolean true/false to integer value to fail, however it is stored as a 1 or 0.
Reproduction steps
Given:
This will result in a
1
invalue
.Using
uint64_t
will throw atype_error
.Expected vs. actual results
I expected all boolean to integer conversions to fail. Instead a
true
->1
andfalse
->0
for certain integer values.Various integer conversions - https://godbolt.org/z/7Wrh6EanW
The
uint64_t
case is taking the path throughget_arithmetic_value
The
int
case is taking the path throughMinimal code example
https://godbolt.org/z/fs4frqz7G
Error messages
No response
Compiler and operating system
Latest MSVC & Clang
Library version
3.11.3
Validation
develop
branch is used.