question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Numbers without decimal numbers are now treated as Double instead of Integers

See original GitHub issue

Describe 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().bodyobject.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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
rybercommented, Dec 21, 2020

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 😀

1reaction
rybercommented, Dec 21, 2020

hrm I could look at pulling this change in, given we have a prescience for ints https://github.com/zenglian/gson/commit/9b7c66d55adf8147c039f90cc4ada93ba494c225

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found