问题
I have to fetch value from list of com.google.gson.JsonPrimitive and put it in List<java.lang.Object>.
I don't know actual type of objects.
Later on some other API will do instanceOf check to get proper data type.
But JsonPrimitive class above does not return object. I can call isNumber, but that returns a LazilyParsedNumber.
Which does not provide isInt etc methods, or access to object so I can call isInstance on it.
EDIT: I have done, getAsDouble. that should work for all except BigInteger and BigDecimal
EDIT2: Since json only has a number data type, it cannot differentiate between float, short, Int, BigDecimal etc. Hence it seems user has to know target data type.
来源:https://stackoverflow.com/questions/43368788/how-to-get-value-as-java-lang-object-from-gson