-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Problem: I need to tell apart long from doubles when generically using a JsonReader
.
Example:
{ "amount" : "93.21948702", "count": 12 }
Today I need to know in advance that one is a double and the other an int/long so I can call nextDouble()
or nextLong()
. I want the reader to provide me enough information so that I can know which one to call or just give me the right object.
Solution 1: Add JSonReader#getPeeked()
and make PEEKED_LONG
and PEEKED_NUMBER
public.
This leave me to do:
if (reader.getPeeked() == JSonReader.PEEKED_LONG) {
return Long.valueOf(reader.nextLong());
}
return Double.valueOf(reader.nextDouble());
Solution 2: Add JsonReader#getNumber()
returns java.lang.Number
.
Which leaves me to do:
reader.nextNumber()
and I can deal with a Double
or Long
down the line.
I can propose a PR but I'd like to know if there are alternatives. Right now I am using, arg, reflection to get to JSonReader.peeked
, PEEKED_LONG
and PEEKED_NUMBER
.