How to get value as java.lang.Object from Gson?

我怕爱的太早我们不能终老 提交于 2019-12-11 04:59:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!