Numbers without decimal numbers are now treated as Double instead of Integers
See original GitHub issueDescribe the bug When an number is returned in a json response with no decimal, I’d expect it to be of type Integer, not type Double.
To Reproduce Steps to reproduce the behavior:
I’m upgrading from the following:
testImplementation("com.konghq:unirest-java:2.3.11")
testImplementation("com.konghq:unirest-objectmapper-jackson:2.3.11")
To:
testImplementation("com.konghq:unirest-java:3.11.06")
testImplementation("com.konghq:unirest-objectmapper-jackson:3.11.06")
I have a json response that returns the following:
{ "integer": 3 }
I’m getting the data like so: Unirest.get("localhost/getInteger").asJson().body
object.toMap()["integer"]
Expected behavior
In version 2 that comes over as a type of Integer
, now it’s coming back as a Double
and failing my tests, as assertEquals(3, 3.0)
is not true.
Environmental Data:
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
Additional context I’m using this inside of a Kotlin application.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Does R treat numbers as double internally? - Stack Overflow
R handles numbers in different ways. In R both integers and double precision float defaults to their 32 bit version.
Read more >In C, why is the real number (e.g. 0.2) by default treated as a ...
If 45.78 be treated as int instead of double then it will be converted into 45 hence there is a loss of two...
Read more >Difference Between float vs double Data Types [Updated]
Float and double are primitive data types used by programming languages to store floating-point real (decimal) numbers like 10.923455, 433.45554598 and so ...
Read more >Integers Floats / Examples / Processing.org
Integers and floats are two different kinds of numerical data. An integer (more commonly called an int) is a number without a decimal...
Read more >Fortran Lesson 3
Examples of numbers not considered integers by Fortran are ... Because of the decimal points, Fortran will regard 3. and 4.0 as real...
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 Free
Top 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
It wasn’t intentional. I’ll look at getting in a patch to fix it. I noticed Google has like 20 different very angry issues about it I get that they wouldn’t at this point want to break backwards compatibility. Luckily our backwards is more sane 😀
hrm I could look at pulling this change in, given we have a prescience for ints https://github.com/zenglian/gson/commit/9b7c66d55adf8147c039f90cc4ada93ba494c225