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.

Double cannot be casted to Integer.

See original GitHub issue

Long cannot be casted to Integer, Integer cannot be casted to Short, etc. Could you fix it in https://github.com/google/gson/blob/master/gson/src/main/java/com/google/gson/internal/bind/ObjectTypeAdapter.java? When serializing Map<String, Object> and deserializing, it throws Exception. I can’t edit this, because I can’t edit Spigot/Bukkit. If JSON save Integer, it should read Integer, not make Double unnecessarily.

I maked it in issue, because I had to download sources GSON and edit this:.

    case NUMBER:
      try {
        return in.nextInt();
      } catch(NumberFormatException exception) {
      }
      try {
        return in.nextLong();
      } catch(NumberFormatException exception) {
      }
      return in.nextDouble();

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:23

github_iconTop GitHub Comments

4reactions
oleersoycommented, Oct 7, 2015

Could the convention be that anything missing a . is an integer and anything with a . is a double?

1reaction
iamMehedicommented, Oct 9, 2017

Is there a way to override this behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cast Double to Integer in Java - Stack Overflow
You cannot directly cast an Integer to a Double object. Also Double and Integer are immutable objects, so you cannot modify them in...
Read more >
Convert Double to Integer in Java - GeeksforGeeks
Approach 1: Using TypeCasting. This technique is very simple and user-friendly. Syntax: double data = 3452.345 int value = (int)data;.
Read more >
How to convert double to int in Java? Example - Javarevisited
The simplest way to convert double to int in Java is by downcasting it. This will return you the non-fractional part of the...
Read more >
How to convert a double to int in Java - Educative.io
1. class DoubleToInt { ; 2. public static void main( String args[] ) { ; 3. double DoubleValue = 3.6987; ; 4. int...
Read more >
java.lang.Double cannot be cast to java.lang.Integer
Conversation of datatypes produces the error below as the batch count is passed as string instead of Integer: java.lang.Double cannot be cast to....
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