Open DieterDePaepe opened 7 years ago
How about returning an Optional<> for get methods instead of throwing/catching exceptions or returning defaults? This way JsonObjects does not have to return null, we get type checking, avoid exception handling and does not have to add new methods for each object type.
@codingchili Optional definitely breaks compatiblity
@DieterDePaepe perhaps hasInteger(String key) ?
@codingchili that being said Optional is nice
Optional would be the best solution, I would consider it when upgrading the major version.
Keeping the restriction in mind, one workaround would be getOptInteger()
.
Alternatively, the hasInteger()
suggestion is also fine by me, though I prefer an approach using Optional
.
Currently, JsonObject has multiple getXXX methods for the basic data types (Integer, Long, String...).
There currently isn't a method to check whether a value holds the expected data type. It can be done by using above methods and catching the
ClassCastException
, but it seems better to provide methods like: