Numeric value for a boolean value is accepted.
See original GitHub issueDescribe the bug A numeric value for a boolean value is accepted. Any numeric value besides 0 ends up in the boolean value getting set to true. 0 will set it to false. Using the openapi-generator to generate the code where there is a boolean property in the request body. Note this is for requests where the value is not in quotes. If the value is in quotes only true or false is accepted.
Version information jackson-databind 2.11.2 openapi-generator 4.2.3
To Reproduce
Body of rest request.
{ "booleanProperty": 9 }
Outcome
<html><body>Value | Boolean value set to |
---|---|
0 | false |
1 | true |
9 | true |
-1 | true |
Expected behavior Only 0 or 1 should be accepted as valid options besides true or false. A config option should be available so that only true or false are valid options.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Boolean values - IBM
A Boolean value represents a truth value; that is, TRUE or FALSE. A Boolean expression or predicate can result in a value of...
Read more >Boolean or truth values - Analytica Wiki
A Boolean or truth value can be True and False , or, equivalently, the number 1 or 0. For example: ... It actually...
Read more >Boolean data type - Wikipedia
In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values (usually denoted true...
Read more >In Javascript, do integer values of 0/1 evaluate the same as ...
In Javascript, do if/while/do-while statements evaluate a 0 or 1 as they would a Boolean variable (true/false)? In the introduction code to Dragon...
Read more >Boolean Data Type - Visual Basic | Microsoft Learn
When Visual Basic converts numeric data type values to Boolean , 0 becomes False and all other values become True . When Visual...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@johnreilly100 godo stuff man glad it’s sorted out -
(-1) is true in boolean cause of JavaScript, COBOL, BASIC, and any other linear language 😉
By programming rules - quote - “All values are truthy unless they are defined as falsy (i.e., except for false, 0, “”, null, undefined, and NaN).” https://stackoverflow.com/questions/34726070/in-javascript-is-1-true-or-false https://www.tutorialspoint.com/cobol/cobol_condition_statements.htm
I know what you say sounds right, and to a normal human it would make sense - but, not in our world 😃
As per @GedMarc, this is a feature, not bug. A few coercions are accepted: originally this particular one was due to languages like C and Perl not having native boolean types.
But it is possible to prevent this acceptance using CoercionConfig, explained ff.ex here:
https://cowtowncoder.medium.com/jackson-2-12-most-wanted-4-5-cbc91c00bcd2
and the example case:
which specifically makes this coercion fail.
Existing default can not really be changed for Jackson 2.x for backwards compatibility.